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.
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"]
I have tried to search and make changes as per answers for above question, but not working. I am not using any build tool.
All the jar files jstl1.2, common loggings 1.1.3 , and Spring 3.2.3 jars are in WebContent/WEB-INF/lib
index.jsp is welcome file is shown properly in Eclipse browser, but when I click on hyperlink for controller, give 404 Requested resource not available. From the log seems tomcat is not loading dispatcher servlet
I tried restarting/clean and publish tomcat,
using tomcat 7, jre7, eclipse kepller 4.0, with java ee 2.0
Appreciate your help
Tomcat logs:
ul 02, 2013 1:16:52 PM org.apache.catalina.core.ApplicationContext log
I**NFO: No Spring WebApplicationInitializer types detected on classpath
Jul 02, 2013 1:16:52 PM org.apache.catalina.core.ApplicationContext log
INFO: Marking servlet spring as unavailable
Jul 02, 2013 1:16:52 PM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet /SpringMVC threw load() exception
java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet**
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1088)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5407)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Jul 02, 2013 1:16:53 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Jul 02, 2013 1:16:53 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 02, 2013 1:16:53 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 11462 ms
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>SpringMVC</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
spring-servlet.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"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
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="com.maverick.springmvc.controller" />
<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>
</beans>
HelloWorldController.java
package com.maverick.springmvc.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
#Controller
public class HelloWorldController {
#RequestMapping("/hello")
public ModelAndView helloWorld() {
System.out.println("test");
String message = "Hello World, Spring 3.0!";
return new ModelAndView("hello", "message", message);
}
}
Based on the stack trace you are missing spring-webmvc.jar which contains DispatcherServlet class. Try check your classpath again (WEB-INF/lib) to make sure that jar is there. Typically on a Spring MVC application you'll need these jars:
I also recommend you use dependency management tool (eg: Maven / ivy) otherwise it's too hard to manage the jars yourselves
Just add all needed jar files to WEB-INF/lib folder, then it works for me.
in this case only that DispatcherServlet class found
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.
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)
I am new to Spring MVC, trying to implement Spring Security features. When I modify the web.xml file I get this kind of error in Catalina log:
27.11.2012 9:49:21 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
The web.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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">
<!-- 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/security-context.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>
<!-- 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>app</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/appServlet/app-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
<url-pattern>*.png</url-pattern>
<url-pattern>*.js</url-pattern>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<!--CharsetFilter start-->
<filter>
<filter-name>CharsetFilter</filter-name>
<filter-class>kz.bimash.FoodSec.filters.CharsetFilter</filter-class>
<init-param>
<param-name>requestEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
</web-app>
This code gives me an error, but when I tried to remove the Spring Security configuration part, it started to work fine. Could you correct my errors in web.xml?
Here is the Apache log file:
27.11.2012 10:57:37 org.apache.catalina.util.LifecycleBase stop
INFO: The stop() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/foodsec]] after stop() had already been called. The second call will be ignored.
27.11.2012 10:57:38 org.apache.catalina.startup.HostConfig deleteRedeployResources
INFO: Undeploying context [/foodsec]
27.11.2012 10:57:38 org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\Program Files\Apache Software Foundation\tomcat7\conf\Catalina\localhost\foodsec.xml
27.11.2012 10:57:45 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
27.11.2012 10:57:45 org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/foodsec] startup failed due to previous errors
Could be a problem with your multiple configs:
<param-value>/WEB-INF/spring/root-context.xml /WEB-INF/spring/appServlet/security-context.xml
Try using a comma instead:
<param-value>/WEB-INF/spring/root-context.xml,/WEB-INF/spring/appServlet/security-context.xml
Best practice is to use wildcards, like this:
<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
And then have your context files named as:
src/main/resources/META-INF/spring/applicationContext.xml
src/main/resources/META-INF/spring/applicationContext-security.xml
You need to start using some logging framework. (put logging framework jars on your classpath)
Without deploy logs no-one is going to help you (we don't like to guess).
Take a look at the tutorial: http://fauzimh.wordpress.com/2011/01/26/spring-3-framework-hello-world-using-eclipse-slf4j-and-logback/
So now enable SLF4J and Logback in your project.
After enabling it, you should get information in Tomcat logs why your Spring XML configuration is bad. Use that information to solve your problem. Yes, I think the problem is not in your web.xml but in your Spring context files.