I am developing a spring application using version 3.1.2 using tomcat 7 as the servlet manager. I have noticed that the beans are being created twice, and I'm not sure how to prevent that. I understand that the issue is somewhere in my web.xml or application context, but I've been unable to locate the source of the duplication.
From the tomcat logs on startup, I see the following (paraphrasing for space):
May 24, 2013 9:33:03 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
May 24, 2013 9:33:03 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Fri May 24 09:33:03 CDT 2013]; root of context hierarchy
May 24, 2013 9:33:03 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/kpi-reporter-servlet.xml]
May 24, 2013 9:33:03 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#df9978: defining beans [...]; root of factory hierarchy
May 24, 2013 9:33:04 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 1260 ms
May 24, 2013 9:33:04 AM org.springframework.web.servlet.FrameworkServlet initServletBean
INFO: FrameworkServlet 'kpi-reporter': initialization started
May 24, 2013 9:33:04 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing WebApplicationContext for namespace 'kpi-reporter-servlet': startup date [Fri May 24 09:33:04 CDT 2013]; parent: Root WebApplicationContext
May 24, 2013 9:33:04 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/kpi-reporter-servlet.xml]
May 24, 2013 9:33:04 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#2821db: defining beans [...]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory#df9978
Here is my web.xml and the application context configurations:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>kpi-reporter</display-name>
<servlet>
<servlet-name>kpi-reporter</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>kpi-reporter</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
<url-pattern>*.gif</url-pattern>
<url-pattern>*.js</url-pattern>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/kpi-reporter-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
kpi-reporter-servlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="."/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"></property>
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
If I remove the statement in the kpi-reporter-servlet.xml, then the beans don't get defined at all. If I move the context statement to the web.xml (along with the required imports) it still gets defined twice. I am suspecting that somehow the web.xml is being called twice during startup.
I've checked the webapps directory, and I only have one file and directory present, the .war file used to deploy the application, and the directory it was unpacked into.
Other .war applications I've developed also have this behavior, though they have similar xml files associated with them.
Does anyone know why this may be happening? I'm stumped over here.
Thanks in advance,
Max
You can comment out the context-param section, something like this:
<!--context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/kpi-reporter-servlet.xml</param-value>
</context-param-->
Or, rename kpi-reporter-servlet.xml to something else, and update context-param's param-value accordingly.
Spring's doc says:
Upon initialization of a DispatcherServlet, Spring MVC looks for a
file named [servlet-name]- servlet.xml...
So in your case, it's like kpi-reporter-servlet.xml is declared twice.
Sring initialize two application contexts here :
The ContextLoaderListener create an application context with the beans contained in the file referenced by your context-param tag :
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/kpi-reporter-servlet.xml</param-value>
</context-param>
This is the "root" (or parent) application context.
Then your DispatcherServlet is looking for a file named SERVLET-NAME-servlet.xml and build another application context with the beans defined in the file. This application context will have the "root" application context as parent. Here your servlet's name is "kpi-reporter" so it loads all beans defined in "kpi-reporter-servlet.xml".
So, if you don't need to use a ContextLoaderListener then remove it. If you need it change the name of the file (for example : kpi-reporter-context.xml) and provide an empty kpi-reporter-servlet.xml which will be loaded by the DispatcherServlet.
Related
Here is the web.xml, after i run the application locally in intelli J, i did‘t see any logs about listener loading
and it doesn't send any errors out, but when i access the controller by http request , and i found the commonData class hadn't be loading
Here is the web.xml, after i run the application locally in intelli J, i did‘t see any logs about listener loading
and it doesn't send any errors out, but when i access the controller by http request , and i found the commonData class hadn't be loading
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>aaa-qa</display-name>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.netease.cloud.aaa.utils.CommonData</listener-class>
</listener>
<filter>
<filter-name>webContextHolderPopulateFilter</filter-name>
<filter-class>com.netease.cloud.nce.filter.WebContextHolderPopulateFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>webContextHolderPopulateFilter</filter-name>
<servlet-name>mvc-dispatcher</servlet-name>
</filter-mapping>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<error-page>
<error-code>404</error-code>
<location>/404error</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/500error</location>
</error-page>
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
</web-app>
Below is the console output in intelli J
23, 2018 3:25:14 下午 org.apache.catalina.core.AprLifecycleListener init
The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/sanqian/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
23, 2018 3:25:15 下午 org.apache.coyote.AbstractProtocol init
Initializing ProtocolHandler ["http-bio-8112"]
23, 2018 3:25:15 下午 org.apache.catalina.core.StandardService startInternal
Starting service Tomcat
23, 2018 3:25:15 下午 org.apache.catalina.core.StandardEngine startInternal
Starting Servlet Engine: Apache Tomcat/7.0.47
23, 2018 3:25:16 下午 org.apache.catalina.startup.ContextConfig getDefaultWebXmlFragment
No global web.xml found
23, 2018 3:25:22 下午 org.apache.catalina.core.ApplicationContext log
No Spring WebApplicationInitializer types detected on classpath
23, 2018 3:25:22 下午 org.apache.catalina.core.ApplicationContext log
Set web app root system property: 'webapp.root' = [/Users/sanqian/nce/workspace/test-code/nce-containerized-test/src/main/webapp/]
23, 2018 3:25:22 下午 org.apache.catalina.core.ApplicationContext log
Initializing Spring root WebApplicationContext
23, 2018 3:25:24 下午 org.apache.catalina.core.ApplicationContext log
Initializing Spring FrameworkServlet 'mvc-dispatcher'
23, 2018 3:25:24 下午 org.apache.coyote.AbstractProtocol start
Starting ProtocolHandler ["http-bio-8112"]
To have a home-page servlet which will generate home page's content, I kept url-pattern empty in the servlet-mapping, which AFAIK maps to the context root, say like mysite.com/ or http://{host}:{port}/mysite/
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>My site</display-name>
<servlet>
<servlet-name>controller</servlet-name>
<servlet-class>com.mysite.control.MainController</servlet-class>
<!-- Load this servlet at server startup time -->
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>controller</servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
The above is the complete web.xml (except root element web-app).
But Tomcat 7.0.26 gives following error during startup due to which the war is not getting deployed.
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/mysite]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:958)
...
Caused by: java.lang.IllegalArgumentException: Invalid <url-pattern> in servlet mapping
at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:3208)
...
Note 1: This is not a spring project, it is pure servlet 3.0 project and just has web.xml configuration at the moment.
Note 2: The class com.mysite.control.MainController does exist.
How can I fix this? I know welcome-file is an option to mimic home page but that is not optimal and I would prefer to fix this instead. Is this tomcat 7.0.26 bug or some other issue?
This is a bug of Tomcat and have been fixed since 7.0.28.
Please refer to this page. So you should update Tomcat.
I need to integrate spring security with a small application built with spring 3.1.1, following this tutorial at the point 3.2.1, got this error trace:
gen 31, 2014 3:08:41 PM org.apache.catalina.core.StandardContext filterStart
Grave: Exception starting filter springSecurityFilterChain
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1097)
at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:326)
at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:236)
at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:194)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:107)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4775)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5452)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:656)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1635)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
gen 31, 2014 3:08:41 PM org.apache.catalina.core.StandardContext startInternal
Grave: Error filterStart
gen 31, 2014 3:08:41 PM org.apache.catalina.core.StandardContext startInternal
Grave: Context [/mmasgis] startup failed due to previous errors
gen 31, 2014 3:08:41 PM org.apache.catalina.core.ApplicationContext log
Informazioni: Closing Spring root WebApplicationContext
INFO : org.springframework.web.context.support.XmlWebApplicationContext - Closing Root WebApplicationContext: startup date [Fri Jan 31 15:08:40 CET 2014]; root of context hierarchy
INFO : org.springframework.beans.factory.support.DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#204ed39b: defining beans [dataSource]; root of factory hierarchy
gen 31, 2014 3:08:41 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
Grave: The web application [/mmasgis] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
gen 31, 2014 3:08:41 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
Grave: The web application [/mmasgis] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak.
gen 31, 2014 3:08:41 PM org.apache.catalina.startup.HostConfig deployDirectory
Informazioni: Deploying web application directory /home/arpho/programmi/sts/springsource/vfabric-tc-server-developer-2.9.3.RELEASE/base-instance/webapps/manager
gen 31, 2014 3:08:41 PM org.apache.catalina.startup.HostConfig deployDirectory
Informazioni: Deploying web application directory /home/arpho/programmi/sts/springsource/vfabric-tc-server-developer-2.9.3.RELEASE/base-instance/webapps/ROOT
gen 31, 2014 3:08:41 PM org.apache.coyote.AbstractProtocol start
Informazioni: Starting ProtocolHandler ["http-bio-8080"]
gen 31, 2014 3:08:41 PM org.apache.catalina.startup.Catalina start
Informazioni: Server startup in 2497 ms
I have referred other threads but with no solution. Can someone correct me where is the problem in the configuration?
Thanks for the time.
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Processes application requests -->
<servlet>
<servlet-name>mmasgisServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mmasgisServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
This is my root-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<bean id="dataSource" name="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="username" value="root"></property>
<property name="password" value="password"></property>
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/mmasgis">
</property>
</bean>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
</beans>
</beans>
Make sure that the security xml is loaded by the ContextLoaderListener and not the DispatcherServlet. The DelegatingFilterProxy will only look into the root applicationcontext (which is loaded by the ContextLoaderListener) for the bean to delegate to. (see spring's documentation here)
In case you only have one dispatcher servlet, you can define your application context globally and leave the dispatcher servlet parameter empty.
Example:
<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml,
/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
</context-param>
<!-- Processes application requests -->
<servlet>
<servlet-name>mmasgisServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
I'm not sure if the web.xml you have given is complete but you must have at least the following in that file:
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
After that, I think you need at least 1 http configuration in your root-context.xml file (I'm not sure about this):
<http auto-config='true'>
<intercept-url pattern="/**" access="ROLE_USER" />
</http>
Most likely you're missing the <http> element from your configuration.
You'll need to create a minimal configuration for Spring Security, using the security namespace:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<http auto-config='true'>
<intercept-url pattern="/**" access="ROLE_USER" />
</http>
</beans:beans>
Also - your XML configuration - if that is a single file, then you don't need to declare the <beans xmlns... element twice.
Hope this helps - I went into some additional details on my blog if you need to digg deeper.
I recently also ran into this problem, and adding the <http> element solved the main problem, but my context initialization still failed. Digging through my Tomcat 8 error log, I noticed the following line buried:
Did you forget to add a global <authentication-manager> element to your configuration
(with child <authentication-provider> elements)? Alternatively you can use the
authentication-manager-ref attribute on your <http> and <global-method-security> elements.
Adding this additional element, which I found in the Spring Security documentation, solved that problem:
<authentication-manager>
<authentication-provider>
<user-service>
<user name="jimi" password="jimispassword" authorities="ROLE_USER, ROLE_ADMIN" />
<user name="bob" password="bobspassword" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
Just wanted to mention it since this problem was related and someone else new to Spring Security may run into it.
I configured a tomcat server for me to deploy a JSP Web Application, but everytime I'll start the website, it prompts in the Tomcat Web Application Manager that FAIL - Application at context path /appNameHere could not be started. Now I'm confuse why this happen, Can someone explain and help why this occured? See detailed error below.
Apr 08, 2013 4:44:30 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Apr 08, 2013 4:44:30 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/appNameHere] startup failed due to previous errors
Apr 08, 2013 4:44:30 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Apr 08, 2013 4:44:33 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
Apr 08, 2013 4:44:34 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.jasypt.exceptions.EncryptionOperationNotPossibleException: Encryption raised an exception. A possible cause is you are using strong encryption algorithms and you have not installed the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files in this Java Virtual Machine
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.handleInvalidKeyException(StandardPBEByteEncryptor.java:819)
at org.jasypt.encryption.pbe.StandardPBEByteEncryptor.decrypt(StandardPBEByteEncryptor.java:796)
at org.jasypt.encryption.pbe.StandardPBEStringEncryptor.decrypt(StandardPBEStringEncryptor.java:639)
at org.jasypt.properties.PropertyValueEncryptionUtils.decrypt(PropertyValueEncryptionUtils.java:72)
at org.jasypt.spring.properties.EncryptablePropertyPlaceholderConfigurer.convertPropertyValue(EncryptablePropertyPlaceholderConfigurer.java:107)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperty(PropertyResourceConfigurer.java:112)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.convertProperties(PropertyResourceConfigurer.java:95)
at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:72)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:663)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:638)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:407)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.manager.ManagerServlet.start(ManagerServlet.java:1276)
at org.apache.catalina.manager.HTMLManagerServlet.start(HTMLManagerServlet.java:625)
at org.apache.catalina.manager.HTMLManagerServlet.doGet(HTMLManagerServlet.java:136)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:194)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:563)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:600)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1703)
at java.lang.Thread.run(Unknown Source)
Apr 08, 2013 4:44:34 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
Apr 08, 2013 4:44:34 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/appNameHere] startup failed due to previous errors
Apr 08, 2013 4:44:34 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
and here's my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<session-config>
<session-timeout>20</session-timeout>
<cookie-config>
<http-only>true</http-only>
<secure>true</secure>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>visitorApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>visitorApp</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/visitorApp-servlet.xml</param-value>
</context-param>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Default page to serve -->
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
</web-app>
Here's the visitorApp-servlet.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<import resource="classes/applicationContext.xml"/>
<!-- JSR-303 support will be detected on classpath and enabled automatically -->
<mvc:annotation-driven/>
<context:component-scan base-package=myPackageNameHere"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:messages"/>
</bean>
</beans>
Is there's something wrong with my listener? Thanks in advance!
If you are storing your encrypted data into a database, check that the table columns that you use to store it are big enough to host the encrypted data (which is always bigger than the original data). If you are transmitting your encrypted data via HTTP, check that you are not having problems with the transmission of BASE64-encoded data as URL parameters (BASE64 uses characters which are forbidden in URL parameters, like "="). For these uses, try using hexadecimal output.
This link would be helpful
The exception indicates that you do not have JCE Policy Jar Files into your JAVA setup.
Download them from http://www.oracle.com/technetwork/java/javase/downloads/jce-7-download-432124.html
Then place the jars inside jdk/lib/security (link)
There is a similar question but the accepted solution did not apply (Issue caused somehow by Spring MVC, which is not the case as it is in this similar question: Spring 3.1 + Hibernate 4.1 JPA, Entity manager factory is registered twice)
To be clear my only issue is the warning that the entity manager factory's(emf) name has been registered twice, I don't have any issues using JPA despite the warning.
So how is the emf name being loaded the first time if spring is not doing it, and should/how_do I stop it?
Environment: Glassfish v 3.1.1, Spring 3.1.1, JPA 2.0 (Hibernate-entity-manager 4.1.0), Struts2
I am getting the following warning:
WARN: HHH000436: Entity manager factory name (empsys) is already registered. If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
Here is part of the server log (last line is the warning, I chopped off the top but rest is continuous):
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
INFO: HHH000412: Hibernate Core {4.1.0.Final}
INFO: HHH000206: hibernate.properties not found
INFO: HHH000021: Bytecode provider name : javassist
INFO: HHH000204: Processing PersistenceUnitInfo [
name: empsys
...]
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
INFO: HHH000397: Using ASTQueryTranslatorFactory
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: PWC1412: WebModule[null] ServletContext.log():No Spring WebApplicationInitializer types detected on classpath
INFO: PWC1412: WebModule[null] ServletContext.log():Initializing Spring root WebApplicationContext
INFO: Root WebApplicationContext: initialization started
INFO: Refreshing Root WebApplicationContext: startup date [Sat Sep 01 19:14:15 MDT 2012]; root of context hierarchy
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
INFO: JSR-250 'javax.annotation.ManagedBean' found and supported for component scanning
INFO: JSR-330 'javax.inject.Named' annotation found and supported for component scanning
INFO: JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
INFO: Bean 'org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter#3170938b' of type [class org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO: Bean 'dataSource' of type [class org.springframework.jndi.JndiObjectFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO: Bean 'dataSource' of type [class com.sun.gjc.spi.jdbc40.DataSource40] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
INFO: Building JPA container EntityManagerFactory for persistence unit 'empsys'
INFO: HHH000204: Processing PersistenceUnitInfo [
name: empsys
...]
INFO: HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLInnoDBDialect
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
INFO: HHH000397: Using ASTQueryTranslatorFactory
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
WARN: HHH000436: Entity manager factory name (empsys) is already registered. If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/index.action</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
<context:annotation-config/>
<context:component-scan base-package="com.kenmcwilliams.employmentsystem" />
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/empsys" />
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!-- <property name="persistenceUnitName" value="empsys" /> -->
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"/>
<tx:annotation-driven transaction-manager="transactionManager"/>
</beans>
persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="empsys" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/empsys</jta-data-source>
<class>com.quaternion.orm.Something</class>
<properties>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.SunOneJtaPlatform"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect"/>
</properties>
</persistence-unit>
</persistence>
It would seem Hibernate is asked to create an EMF for this PU twice. Hibernate tracks each EMF it builds in a registry. This warning is just telling you that an EMF was already registered under that same PU name. As the warning goes on to tell you that can be a problem if you cluster the application using that EMF. Otherwise its just a warning letting you know about the situation (and even how to resolve it).
I believe the issue can be resolved here:
<context:component-scan base-package="com.kenmcwilliams.employmentsystem" />
You should filter out any packages/classes for JPA that are annotated with #Component, especially the one that creates the entity manager bean.
Classes annotated with #Component are scanned by default, at least for root context JPA configurations.
I had the same issue and resolved it by filtering the JPA configuration classes out of the component scan.