Basically I have this jetty server running at my local. But I can't access my index.jsp file I see like that
this is my web.xml file, You see I use Apache CXF, and also use Spring, Hibernate and Jetty
<?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_1.xsd"
version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml,classpath:Spring-Security.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring Security Start -->
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<!-- Projenin ana url'inden itibaren spring security aktif ediliyor -->
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring Security End -->
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
How can I resolve it. Where I am doing wrong ?
This has been answered in a few places on StackOverflow. You simply need to set the dirAllowed parameter to false on the default servlet. This can be done either in the WEB-INF/web.xml of the servlet descriptor or by providing a modified etc/webdefault.xml file (via the deploy module in Jetty, for example) which is loaded before any of the contexts.
In either file this would look like:
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
....
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
....
</servlet>
As user Eng.Fouad points out this can also be defined as a context parameter:
<context-param>
<param-name>org.eclipse.jetty.servlet.Default.dirAllowed</param-name>
<param-value>false</param-value>
</context-param>
Related
I need to serve arbitrary files together with the war. Where do I put it in webapps/$project and configure in web.xml?
web.xml
<?xml version="1.0" encoding="UTF-8" ?>
<web-app
version="4.0"
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_4_0.xsd
"
>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<filter>
<filter-name>httpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
<async-supported>true</async-supported>
</filter>
<filter-mapping>
<filter-name>httpMethodFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!--Spring MVC-->
<servlet>
<servlet-name>servlet</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>
<async-supported>true</async-supported>
</servlet>
<!--End of Spring MVC-->
<servlet-mapping>
<servlet-name>servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>20</session-timeout>
</session-config>
</web-app>
To serve static content such as html, css, etc., put the files under any directory under your $tomcat_home/webapps/$project directory.
$tomcat_home
+--bin
+--conf
+--...
+--webapps
+--your-app (Ex: file-server)
+-- your-static-content-directory (Ex: static)
+--css
+--a.css
+--b.css
+--html
+--index.html
+--contact.html
+-- WEB-INF
Assuming your Tomcat runs on locally on port 8080, you can access the file a.css at http://localhost:8080/file-server/static/css/a.css
In my sample SPring project I'm using the following web.xml,
I think that it fails to properly use
root-context.xml
servlet-context.xml
security-context.xml
How should I change it in order to provide these three configuration files
correctly ?
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appServlet/app-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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>appServlet</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>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Typical the filter-mapping is located after the servlet mapping (Adjusting web.xml listeners, filters and servlets)
One other thing looks strange: you wrote that you have a:
root-context.xml
servlet-context.xml
security-context.xml
Of course the name "root-context.xml" is not standardized, but I expect that his is the spring configuration file that contains the services, DAO, db connection but not the web-controller stuff. If it is so, then you should load your root-context.xml with the "inner-application context" created by ContextLoaderListener and configured by context-param contextConfigLocation. The security-context.xml MUST also been loaded by the ContextLoaderListener, so if there is no import for security-context.xml in root-context.xml then you must configure them both in contextConfigLocation
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/appServlet/root-context.xml,
/WEB-INF/spring/appServlet/app-security-context.xml
</param-value>
</context-param>
Maybe you should have a look at this question: ContextLoaderListener or not? - the question an the accepted answer explain a bit of how the two contexts work.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring-security.xml,
classpath:spring-mybatis.xml
</param-value>
</context-param>
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<!-- 此处可以可以配置成*.do,对应struts的后缀习惯 -->
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 编码过滤器 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Spring监听器 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 防止Spring内存溢出监听器 -->
<listener>
<listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
</web-app>
I have following web application structure:
inside addTerminal.jsp I write following:
....
show map
...
function showMap(lat,lng) {
window.open('map.html?lat='+lat+'&lng='+lng, 'map', 'width=600,height=400');
}
....
But as client cannot access to WEB-INF folder I see 404 when click on href
Can you advice workaround how resolve my issue?
I think I can put map.html into webapp folder but I think exist another fix.
Application technology stack:
Tomcat + Hibernate + SpringMVC
web.xml:
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Spring MVC Application</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/webContext.xml</param-value>
</context-param>
<!-- Spring MVC -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/webContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<!-- Spring Security -->
<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>
<filter>
<filter-name>charsetFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>charsetFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
You simply need to create a controller that handles requests to map.html.
Something similar:
#RequestMapping("/map.html")
public String popup(#RequestParam("lat") String lat, #RequestParam("lng") String lng){
// your code here...
return "map";
}
You can use the mvc:resources tag to load items you consider resources.
<mvc:resources location="/web-inf/<path to html file>" mapping="<url context in a browser>" cache-period="86400"/>
Reference: http://docs.spring.io/spring/docs/4.1.2.BUILD-SNAPSHOT/spring-framework-reference/htmlsingle/#mvc-config-static-resources
I've got an application which is working perfectly fine on Weblogic 11. But when trying to run it on weblogic 12c, I get this exception:
...
Caused by: 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>
at javax.faces.FactoryFinder._getFactory(FactoryFinder.java:286)
at javax.faces.FactoryFinder.getFactory(FactoryFinder.java:206)
...
I've got this listener in my web.xml. I've gone through the first two pages on google search on this topic, but didn't find any solution.
I use:
Apache MyFaces 2.1.10
Servlet API 2.5
Spring 3.2.4
Requested: web.xml
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<!--
- ####################
- Spring configuration
- ####################
//-->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<!--
- Declaration of the SPRING MVC dispatcher servlet.
//-->
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--load-on-startup>1</load-on-startup-->
</servlet>
<servlet>
<servlet-name>pibEmailServlet</servlet-name>
<servlet-class>com.teamead.fwf.web.PibEmailServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>overviewForward</servlet-name>
<servlet-class>com.teamead.fwf.web.OverviewForwardServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>overviewForward</servlet-name>
<url-pattern>/showMenu/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>pibEmailServlet</servlet-name>
<url-pattern>/sendPibEmail</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>aipUpdateServlet</servlet-name>
<servlet-class>com.teamead.fwf.web.AipUpdateServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>aipUpdateServlet</servlet-name>
<url-pattern>/aip/update</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>aipUpdateServlet</servlet-name>
<url-pattern>/aip/reset</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>validationServlet</servlet-name>
<servlet-class>com.teamead.fwf.web.servlet.ValidationServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>validationServlet</servlet-name>
<url-pattern>/validationServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/pib.html</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/pib.pdf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/pib.xml</url-pattern>
</servlet-mapping>
<!--
- Specifies the context location for the root application context of this web app.
- The value mentioned here is the default of the ContextLoaderListener.
//-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring/properties-config.xml
/WEB-INF/spring/menu/menu-config.xml
/WEB-INF/spring/captcha-service.xml
/WEB-INF/spring/custom-message-service.xml
/WEB-INF/spring/data-access.xml
/WEB-INF/spring/data-source.xml
/WEB-INF/spring/service-definition.xml
/WEB-INF/spring/domain-service.xml
/WEB-INF/spring/spring-security-config.xml
/WEB-INF/spring/cms-config.xml
/WEB-INF/spring/predefined-pib.xml
/WEB-INF/spring/fwf-services-manager.xml
</param-value>
</context-param>
<!-- Theme settings for FLAVOUR -->
<!--context-param>
<param-name>primefaces.THEME</param-name>
<param-value>#{siteService.siteTag}-THEME</param-value>
</context-param-->
<!--If this is not set, the XML comments in pages are rendered as components(i.e. in panelGrid)-->
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!--<listener>
<listener-class>com.bea.p13n.http.SessionMonitor</listener-class>
</listener>-->
<!--
- Listener, to allow Jetty serving MyFaces apps.
//-->
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<!--
- Loads the specified root application context of this web app at startup,
- by default from "/WEB-INF/services.xml".
//-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!--
- ##################################
- Tomahawk MyFaces JSF configuration
- ##################################
//-->
<context-param>
<param-name>org.apache.myfaces.JSF_JS_MODE</param-name>
<param-value>minimal-modern</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.VALIDATE_EMPTY_FIELDS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.NUMBER_OF_VIEWS_IN_SESSION</param-name>
<param-value>30</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>
<context-param>
<param-name>facelets.VIEW_MAPPINGS</param-name>
<param-value>/public/*;/restricted/*;/ajaxlogin/*;/mobile/*</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.CHECK_ID_PRODUCTION_MODE</param-name>
<param-value>false</param-value>
</context-param>
<!-- ONLY FOR WEBLOGIC DEPLOYMENT -->
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>2</param-value>
</context-param>
<context-param>
<param-name>primefaces.PRIVATE_CAPTCHA_KEY</param-name>
<param-value>6Ldx8eYSAAAAAI7A7Ln5GjOvQ88YD5HwwXV-KyUR</param-value>
</context-param>
<context-param>
<param-name>primefaces.PUBLIC_CAPTCHA_KEY</param-name>
<param-value>6Ldx8eYSAAAAAIyXv7tZAlOm5IGPYkIO1wLKHKMK</param-value>
</context-param>
<context-param>
<description>
This parameter tells MyFaces if javascript code should be allowed in the
rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default: "true"
</description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.CHECK_EXTENSIONS_FILTER</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
If true, rendered HTML code will be formatted, so that it is "human readable".
i.e. additional line separators and whitespace will be written, that do not
influence the HTML code.
Default: "true"
</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>
/WEB-INF/taglib/messages.taglib.xml;/WEB-INF/taglib/springsecurity.taglib.xml
</param-value>
</context-param>
<!-- if you want to disable the behaviour completely -->
<context-param>
<param-name>org.apache.myfaces.ERROR_HANDLING</param-name>
<param-value>false</param-value>
</context-param>
<!-- if you are using myfaces + facelets don't forget to do this -->
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>false</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Redirect Servlet</servlet-name>
<servlet-class>com.teamead.fwf.web.RedirectServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Redirect Servlet</servlet-name>
<url-pattern>/redirect</url-pattern>
</servlet-mapping>
<!--
- Faces Servlet Mapping.
//-->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<filter>
<filter-name>Character Encoding</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<!--
- Spring Security filter chain.
//-->
<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>
<dispatcher>FORWARD</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<!--
- The corresponding filter mapping
//-->
<filter-mapping>
<filter-name>Character Encoding</filter-name>
<url-pattern>*.faces</url-pattern>
</filter-mapping>
<!--
- Common data source.
//-->
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/CS_PU</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<!--
- Welcome Files.
//-->
<welcome-file-list>
<welcome-file>index.jspx</welcome-file>
</welcome-file-list>
</web-app>
I was using annotated configuration for my Spring web app and then had to mix XML with it so that I could use Spring Security. I annotated one of my configuration classes with #ImportResource("security-config.xml") to load the security config. The configuration beans are being created just fine. My web.xml looks like so:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="com-timbuk2-webapp-compositor"
version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
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" >
<!-- Spring Security Chain -->
<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>
<!-- Character Encoding -->
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- URL Rewrite -->
<filter>
<filter-name>urlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>commons</param-value>
</init-param>
<init-param>
<param-name>confPath</param-name>
<param-value>/WEB-INF/conf/urlrewrite-config.xml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>urlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- Listeners -->
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Context Parameters -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/conf/log4j-config.xml</param-value>
</context-param>
<!-- Servlets -->
<servlet>
<servlet-name>app-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.website.config</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<!-- Servlet mappings -->
<servlet-mapping>
<servlet-name>app-dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
</web-app>
From what I understand the springSecurityFilterChain needs ContextLoaderListener. However, because of how my app is configured, if I add:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
to my web.xml my app doesn't initialize. Is there a way to manually create a ContextLoaderListener in my annotated configuration?
Just create a root application context by using the ContextLoaderListener.
<context-param>
<description>The Spring configuration files.</description>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/application.xml</param-value>
</context-param>
<listener>
<description>The Spring context listener.</description>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
Inside the application.xml, you also can define the annotation based config. It will be inherited by the WebApplicationContext of your DispatcherServlet definition.
Then you import your security configuration inside the application.xml. So security will apply to all ApplicationContexts in your configuration.
I believe it works with the following additions under web-app
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.config.java.context.JavaConfigWebApplicationContext
</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.website.config</param-value>
</context-param>
source : http://blog.springsource.com/2008/03/26/spring-java-configuration-whats-new-in-m3/
Do not forget to add "classpath:/" if your root.xml is somewhere different from the web.xml dir. Hope this will help someone in the future.
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:/appcontext-root.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>