Spring boot JSF 2.0 application run as Jar - maven

I have a spring boot+JSF application which runs as a charm when we run it as:
mvn spring-boot:run
However when i create a jar using mvn clean compile package install
and then run java -jar myapp.jar
i get:
java.lang.IllegalStateException: No Factories configured for this Application. This happens if the faces-initialization does not work at all - make sure that you properly include all configuration settings necessary for a basic faces application and that all the necessary libs are included. Also check the logging output of your web application and your container for any exceptions!
If you did that and find nothing, the mistake might be due to the fact that you use some special web-containers which do not support registering context-listeners via TLD files and a context listener is not setup in your web.xml.
A typical config looks like this;
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
in web xml as suggested here i tried below three options:
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
OR
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
OR
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
However the error remains the same, running out of ideas, appreciate any help on the same.
Best

Related

Difference between Log4jConfigListener and Log4jServletContextListener while configuring log4j

I am trying to deploy a spring web app in tomcat with log4j logging. From what I see from reading up on log4j configuration you can do it as follows -
<context-param>
<param-name>log4jConfiguration</param-name>
<param-value>/WEB-INF/webdynamo-log4j.xml</param-value>
</context-param>
<context-param>
<param-name>log4j.refresh.interval</param-name>
<param-value>120</param-value>
</context-param>
And you also need a listener for this to work -
Couple of places I have seen -
<listener>
<listener-class>
org.apache.logging.log4j.web.Log4jServletContextListener
</listener-class>
</listener>
and some places I have seen
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
Wanted to understand if there is any fundamental difference in using these listeners. I see they are in different packages altogether.

log4j with multiple applications in websphere

I have two applications (war) deployed on a single websphere application server. Both applications have their own log4j properties and they are loaded from their respective web.xml as
From web.xml of App1
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:app1/app1Log4j.properties</param-value>
</context-param>
From web.xml of App2
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:app2/app2Log4j.properties</param-value>
</context-param>
Both applications create separate log files.
The problem I'm facing is When I restart the app server, log file for only one application is created. Log statements for 2nd application dont get written to any file. If I stop and start app2 again, then log files for app2 get created and logs are written for both the application.
I verified that the classloader policy at server level is "Multiple" and "parent last". Enabled the class loader service and verified that for both apps log4j.jar is loaded from WEB-INF/lib of corresponding wars. I even tried to set different "start order" for both apps, disabled "parallel start" at server level. But none of the options helped.
Both the log files get written when I start the applications individually after a delay, but one of them dont get written if I start them at the same time. Any help on how to overcome this problem is greatly appreciated.
Thanks,
SMan

Spring project not creating spring-config.xml

I have read some tutorials about using spring, and I've seen they speak about "spring-config.xml", but when I create a project I don't have that file, I have "application-config.xml", are they the same? Is the former the updated version of the latter? I am using Eclipse as IDE
The Spring Context only defines the concept of creating a Spring configuration where you will define spring components (beans, services, etc)
The XML itself can be named whatever you want, but in the web.xml file, you have to pass the xml name you choose to the spring context listener
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/thisXMLhaTheBestNameEver.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

load spring context

I use intelliJ Idea 10.5. when i use context-param for for spring context and run project Tomcat show me blank page!! when I disable it, page show!
<context-param>
<param-name>contextLocation</param-name>
<param-value>classpath:context/applicationContext-dao.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
You need to enable log4j and see the exception Spring is throwing when you start tomcat.. Also make sure that the context file is in the war file (on the location - WEB-INF/classes/context/applicationContext-dao.xml
Ian.

java.lang.IllegalStateException: Root context attribute is not of type WebApplicationContext

I am deploying Portlets on Liferay 5.2.3 on Tomcat 6. I get this error only for one of the portlet.
java.lang.IllegalStateException: Root context attribute is not of type WebApplicationContext
I did some research and found out that Spring was instantiating a portlet application context when it need a web one. But in my web.xml I am only defining contextLoaderListner
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
And to top it off, if a different *.jar file was being looked up by Spring, then why would my other portlets get deployed except one?
After couple of redeployments I get that to a fix. Can someone put some light on?
The root cause seems to be a static variable in the portal/application server "hanging onto" an instance of a class from the portlet. Two common culprits are log4j and java logging, both of which are commonly used by application containters.
See log4j and the thread context classloader and http://logback.qos.ch/manual/loggingSeparation.html for more discussion of loggers. The suggestion is to use SLF4J with logback OR to be sure to put log4j.jar in your WAR file so it is in the right classloader (although some containers will thwart this solution).
Also, some other class that is present in the container may be the cause. Logging is just a common problem.
Sounds like you are not defining the contextConfigLocation? in web.xml you should also have something like this in addition to the contextLoaderListener:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Where applicationContext.xml is a normal config file for a webapp.
You should also have this in your web.xml if using spring portlet MVC:
<servlet>
<servlet-name>ViewRendererServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ViewRendererServlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
In your portlet.xml I guess you have something like this to specify your portlets:
<portlet>
<portlet-name>sample</portlet-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>view</portlet-mode>
</supports>
<portlet-info>
<title>Sample Portlet</title>
</portlet-info>
</portlet>
If you haven't already, see the spring portlet mvc reference documentation
Hope it helps.

Resources