Results 1 to 4 of 4
  1. #1
    esolve is offline Member
    Join Date
    Mar 2015
    Posts
    56
    Rep Power
    0

    Default 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>
    and I find that there is no Spring configuration (as below) in the web.xml (as above)

    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>
    but there is a beans.xml in the project which manages beans through annotaions (component-scan)

    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?

  2. #2
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default 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.

  3. #3
    esolve is offline Member
    Join Date
    Mar 2015
    Posts
    56
    Rep Power
    0

    Default 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>
    why?

    is it that both are OK?

  4. #4
    benji2505 is offline Senior Member
    Join Date
    Sep 2014
    Location
    MA, USA
    Posts
    398
    Rep Power
    5

    Default 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

  1. Spring MVC - Java based configuration
    By TheJudge in forum New To Java
    Replies: 1
    Last Post: 08-18-2014, 03:12 PM
  2. Replies: 1
    Last Post: 12-27-2010, 05:21 PM
  3. Spring Configuration Error - XML issue?
    By hofsoc in forum New To Java
    Replies: 0
    Last Post: 09-20-2010, 03:21 PM
  4. Replies: 0
    Last Post: 04-01-2008, 10:45 AM
  5. Replies: 0
    Last Post: 10-04-2007, 09:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •