Announcement Announcement Module
Collapse
No announcement yet.
Breaking application in different modules Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Breaking application in different modules

    Hello !

    I am trying to break my appliation in different spring modules. Each module will have its own configuration files, handlers, database logic etc. The idea is to reuse a complete functional logic in any web application by adding just a single jar.

    Following is the configuration

    for a module a create a seperate project with following directory structure

    SeperateModule
    |
    ---actionhandler
    | |
    | ---TestHandler.java
    |
    ---config
    |
    ---SeperateModule.xml


    the SeperateModule.xml file contains the applicationcontext for TestHandler

    <beans>
    <bean class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <value>
    /*.test=testHandler
    </value>
    </property>
    <property name="JDBCTemplate">
    <ref bean="JDBCTemplate"/>
    </property>
    </bean>

    <bean name="testHandler" class="com.avanza.ambit.actionhandler.TestHandler" />

    <bean id="viewResolver" class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="prefix" value="/"/>
    <property name="suffix" value=""/>
    </bean>

    </beans>



    The main applicationcontext is as follows

    <beans>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    <property
    name="driverClassName"><value>com.microsoft.sqlser ver.jdbc.SQLServerDriver</value></property>
    <property name="url"><value>jdbc:sqlserver://testserver;databaseName=testdb;sendStringParameter sAsUnicode=true</value></property>
    <property name="username"><value>test</value></property>
    <property name="password"><value></value></property>
    </bean>

    <bean id="JDBCTemplate"
    class="org.springframework.jdbc.core.JdbcTemplate" >
    <constructor-arg index="0"><ref bean="dataSource" /></constructor-arg>
    </bean>
    </beans>


    and the web.xml is as follows

    <servlet>
    <servlet-name>seperatemodule</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <init-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    classpath:config/SeperateModule.xml
    </param-value>
    </init-param>
    </servlet>

    <servlet-mapping>
    <servlet-name>seperatemodule</servlet-name>
    <url-pattern>*.test</url-pattern>
    </servlet-mapping>


    The handler is correctly called but I was unable to use the JDBCTemplate bean define in main applicationcontext.xml in my module context file i.e. SeperateModule.xml

    I believe there should be no problems accessing it ... but unable to understand why this exception is occured.

    Error creating bean with name 'org.springframework.web.servlet.handler.SimpleUrl HandlerMapping' defined in class path resource [SeperateModule.xml]: Cannot resolve reference to bean 'JDBCTemplate' while setting bean property 'JDBCTemplate'; nested exception is org.springframework.beans.factory.NoSuchBeanDefini tionException: No bean named 'JDBCTemplate' is defined

  • #2
    It appears that the child definition doesn't know about the beans defined in the parent. Have you tried simply specifying multiple applicationContext files to load with ContextLoaderListener instead?

    Comment

    Working...
    X