Results 1 to 4 of 4
- 12-09-2016, 02:06 AM #1
Member
- Join Date
- Mar 2015
- Posts
- 56
- Rep Power
- 0
NO Spring configuration in web.xml
I'm reading source codes of a project
Java Code:<?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>filter</filter-name> <filter-class>cn.itcast.elec.filter.LogonFilter</filter-class> </filter> <filter-mapping> <filter-name>filter</filter-name> <url-pattern>*.do</url-pattern> </filter-mapping> <filter-mapping> <filter-name>filter</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping> <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> <servlet> <servlet-name>checkLogonName</servlet-name> <servlet-class>cn.itcast.elec.servlet.CheckLogonName</servlet-class> </servlet> <servlet-mapping> <servlet-name>checkLogonName</servlet-name> <url-pattern>/checkLogonName</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</session-timeout> </session-config> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
Java Code:<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:beans.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
in my opinion, there should be spring configuration in web.xml, otherwise how can the program know where and how to load beans.xml?
can anyone tell me what is wrong with my thinking?
- 12-09-2016, 06:12 AM #2
Senior Member
- Join Date
- Sep 2014
- Location
- MA, USA
- Posts
- 399
- Rep Power
- 7
Re: NO Spring configuration in web.xml
In the web.xml file you only find the dispatcher servlet definition. Since it is Spring it will look for a spring bean configuration file in the WEB-INF folder. The name should be checkLogonName-servlet.xml.
- 12-09-2016, 07:30 AM #3
Member
- Join Date
- Mar 2015
- Posts
- 56
- Rep Power
- 0
Re: NO Spring configuration in web.xml
no, it is "beans.xml", not checkLogonName-servlet.xml. And it is in the "src" folder, and thus it is also in the WEB-INF->classses folder
so you mean the spring will automatically search for beans.xml file within the WEB-INF folder or its sub-folders?
but I also see the following code segment within web.xml file
Java Code:<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:beans.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param>
is it that both are OK?
- 12-09-2016, 05:17 PM #4
Senior Member
- Join Date
- Sep 2014
- Location
- MA, USA
- Posts
- 399
- Rep Power
- 7
Re: NO Spring configuration in web.xml
ok, the code points to the beans.xml file in the classpath and Spring will search for that and get the annotation info from there. Different authors have different setups and the code above does not reveal the general structure of the project. The author might have stuffed everything into the beans.xml file.
I usually use boiler-plate setups and they look different. I usually have a separate xml file for the database, the controllers and the classes where the actual mojo happens. All this info would be in the web.xml file just as in post #3.
Similar Threads
-
Spring MVC - Java based configuration
By TheJudge in forum New To JavaReplies: 1Last Post: 08-18-2014, 04:12 PM -
possible overlapping jars in spring annotated mvc/spring security project
By savantics in forum Web FrameworksReplies: 1Last Post: 12-27-2010, 06:21 PM -
Spring Configuration Error - XML issue?
By hofsoc in forum New To JavaReplies: 0Last Post: 09-20-2010, 04:21 PM -
XML-based configuration metadata in Spring Framework
By Java Tip in forum Java TipReplies: 0Last Post: 04-01-2008, 11:45 AM -
XML-based configuration metadata in Spring Framework
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 10:17 PM
Bookmarks