Announcement Announcement Module
Collapse
No announcement yet.
Not able to split the config file. getting no respose Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not able to split the config file. getting no respose

    I have erSpring-servlet.xml as the config file. Everything works fine. Now I want to take out admin related funtionalities from this config file and put it in a seperate config file named applicationContext-admin.xml.

    Here is my applicationContext-admin.xml file
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
    	<!-- ========================= URL MAPPING DEFINITIONS ========================= -->
    	<bean id="urlMapping"
    		class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<props>
    				<prop key="/admin.htm">adminController</prop>			
    			</props>
    		</property>
    	</bean>
    
    	<bean id="adminController"
    		class="com.dbt.erspring.controller.AdminController">
    	</bean>
    		
    
    	<!-- ========================= MESSAGE RESOURCE DEFINITIONS ========================= -->
    	<bean id="messageSource"
    		class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basename">
    			<value>messages</value>
    		</property>
    	</bean>
    
    	<!-- ========================= VIEW RESOLVER DEFINITIONS ========================= -->
    	<bean id="viewResolver"
    		class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    		<property name="basename">
    			<value>views</value>
    		</property>
    	</bean>
    
    </beans>
    Here is my modified web.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http&#58;//java.sun.com/xml/ns/j2ee"
    	xmlns&#58;xsi="http&#58;//www.w3.org/2001/XMLSchema-instance"
    	xsi&#58;schemaLocation="http&#58;//java.sun.com/xml/ns/j2ee 
    	http&#58;//java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    
    
    	<display-name>erSpring</display-name>
    	<description>Spring implementation of er application</description>
    
    
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    			/WEB-INF/applicationContext-hibernate.xml,
    			/WEB-INF/applicationContext-admin.xml
    		</param-value>
    	</context-param>
    
    
    
    	<listener>
    		<listener-class>
    			org.springframework.web.context.ContextLoaderListener
    		</listener-class>
    	</listener>
    
    	<servlet>
    		<servlet-name>erSpring</servlet-name>
    		<servlet-class>
    			org.springframework.web.servlet.DispatcherServlet
    		</servlet-class>
    		<load-on-startup>2</load-on-startup>
    	</servlet>
    
    	<servlet-mapping>
    		<servlet-name>erSpring</servlet-name>
    		<url-pattern>*.htm</url-pattern>
    	</servlet-mapping>
    	<session-config>
    		<session-timeout>10</session-timeout>
    	</session-config>
    	<welcome-file-list>
    		<welcome-file>index.jsp</welcome-file>
    	</welcome-file-list>
    	<error-page>
    		<exception-type>java.lang.Exception</exception-type>		
    		<location>/WEB-INF/jsp/error.jsp</location>
    	</error-page>
    </web-app>

    Afte the refactoring when I visit http://localhost/erSpring/admin.htm I get 404 error. Am I missing something. The non-admin part works fine and also the persistence layer for the non-admin part works.

    Any suggestions.

    - Neeraj

  • #2
    Maybe you are not deploying the -admin.xml file in your jar? You can also use the <include> directive:
    http://www.springframework.org/docs/...context-import
    If you still have problems activate the logging and see what does Spring do at startup.

    Comment


    • #3
      the log looks fine ..

      The log looks fine to me ...

      INFO (org.springframework.web.servlet.handler.AbstractU rlHandlerMapping:registerHandler:175) - Mapped URL path [/admin.htm] onto handler [com.dbt.erspring.controller.AdminController@1a0b94 d]


      Am I accessing the site correctly? http://localhost/erSpring/admin.htm . The log says that /admin.htm is properly mapped still I'm not able to access it.


      Code:
      INFO &#40;org.springframework.beans.factory.xml.XmlBeanDefinitionReader&#58;loadBeanDefinitions&#58;119&#41; - Loading XML bean definitions from ServletContext resource &#91;/WEB-INF/applicationContext-admin.xml&#93;
      .....
      DEBUG &#40;org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory&#58;createBean&#58;280&#41; - Creating instance of bean 'messageSource' with merged definition &#91;Root bean with class &#91;org.spring
      framework.context.support.ResourceBundleMessageSource&#93; defined in ServletContext resource &#91;/WEB-INF/applicationContext-admin.xml&#93;&#93;
      ..........
      DEBUG &#40;org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory&#58;createBean&#58;280&#41; - Creating instance of bean 'urlMapping' with merged definition &#91;Root bean with class &#91;org.springfra
      mework.web.servlet.handler.SimpleUrlHandlerMapping&#93; defined in ServletContext resource &#91;/WEB-INF/applicationContext-admin.xml&#93;&#93;
      ...................................................
      INFO &#40;org.springframework.beans.factory.support.AbstractBeanFactory&#58;getBean&#58;217&#41; - Creating shared instance of singleton bean 'adminController'
      DEBUG &#40;org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory&#58;createBean&#58;280&#41; - Creating instance of bean 'adminController' with merged definition &#91;Root bean with class &#91;com.dbt.
      erspring.controller.AdminController&#93; defined in ServletContext resource &#91;/WEB-INF/applicationContext-admin.xml&#93;&#93;
      DEBUG &#40;org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory&#58;applyBeanPostProcessorsBeforeInitialization&#58;199&#41; - Invoking BeanPostProcessors before initialization of bean 'adminC
      ontroller'
      DEBUG &#40;org.springframework.context.support.ApplicationContextAwareProcessor&#58;postProcessBeforeInitialization&#58;78&#41; - Invoking setApplicationContext on ApplicationContextAware bean 'adminController'
      DEBUG &#40;org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory&#58;applyBeanPostProcessorsAfterInitialization&#58;234&#41; - Invoking BeanPostProcessors after initialization of bean 'adminCon
      troller'
      
      &#91;b&#93;INFO &#40;org.springframework.web.servlet.handler.AbstractUrlHandlerMapping&#58;registerHandler&#58;175&#41; - Mapped URL path &#91;/admin.htm&#93; onto handler &#91;/b&#93;&#91;com.dbt.erspring.controller.AdminController@1a0b94d&#93;


      - Neeraj

      Comment


      • #4
        Just for clarification: I presume the "erSpring" in your URL http://localhost/erSpring/admin.htm is your web context root? That is, your webapp is definitely deployed under the that context root?

        Tim

        Comment


        • #5
          Looking at this, to access the url http://localhost/erSpring/admin.htm, should this:
          Code:
             <servlet-mapping>
                <servlet-name>erSpring</servlet-name>
                <url-pattern>*.htm</url-pattern>
             </servlet-mapping>
          not be:

          Code:
             <servlet-mapping>
                <servlet-name>erSpring</servlet-name>
                <url-pattern>/erSpring/*</url-pattern>
             </servlet-mapping>
          Unless the webapp context is erSpring, as timmorrow asked.

          Comment


          • #6
            context defintion looks okay

            As I mentioned in the web.xml above the erspring is defined this way..
            Code:
            <servlet-mapping>
                  <servlet-name>erSpring</servlet-name>
                  <url-pattern>*.htm</url-pattern>
               </servlet-mapping>

            If I keep all my admin configuration then the link works fine but when I refactor the config file to take out the admin related beans to applicationContext-admin.xml file those admin links stop working. Still clueless. BTW I am testing on tomcat 5.0 and am running spring 1.1.4

            - Neeraj

            Comment


            • #7
              Hang on - do you also have an erSpring-servlet.xml file that defines non-admin stuff specific to this servlet? Are you just trying to factor out part of this servlet config to a separate file?

              If that's the case, try this:

              Code:
                 <servlet> 
                    <servlet-name>erSpring</servlet-name> 
                    <servlet-class> 
                       org.springframework.web.servlet.DispatcherServlet 
                    </servlet-class> 
                    <param-name>contextConfigLocation</param-name>
                    <param-value>/WEB-INF/erSpring-servlet.xml,/WEB-INF/applicationContext-admin.xml</param-value>
                    <load-on-startup>2</load-on-startup> 
                 </servlet>

              Comment


              • #8
                This is confusing ...

                I guess time has come to open up the source file and look under the hood what's going on. I implemented the solution suggested by dhewitt with a change [init-param was added]. Here is the new code ..
                Code:
                	<context-param>
                		<param-name>contextConfigLocation</param-name>
                		<param-value>
                			/WEB-INF/applicationContext-hibernate.xml,/WEB-INF/applicationContext-admin.xml
                		</param-value>
                	</context-param>
                
                	<servlet>
                		<servlet-name>erSpring</servlet-name>
                		<servlet-class>
                			org.springframework.web.servlet.DispatcherServlet
                		</servlet-class>
                		<init-param>
                			<param-name>contextConfigLocation</param-name>
                			<param-value>
                				/WEB-INF/applicationContext-hibernate.xml,/WEB-INF/applicationContext-admin.xml
                			</param-value>
                		</init-param>
                		<load-on-startup>2</load-on-startup>
                	</servlet>
                Now
                1) http://localhost/erSpring/admin.htm works.
                2) Access to datbase, I mean hibernate work for the admin site.
                3) Non-admin site doesn't work. http://localhost/erSpring/index.htm doesn't work.

                I also tried passing the /web-inf/erSpring-servlet.xml to the servlet in the init parm still the non-admin site doesn't work. Log doesn't show anything wrong. Has anyone else successfully implemented having two configuration files?

                Thanks to all.

                Comment


                • #9
                  Can you post the contents of you applicationContext-hibernate.xml file? Something is conflicting, and I can't tell what without seeing that file really.

                  Comment

                  Working...
                  X