Announcement Announcement Module
No announcement yet.
Breaking application in different modules Page Title Module
Move Remove Collapse
Conversation Detail Module
  • 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

    | |

    the SeperateModule.xml file contains the applicationcontext for TestHandler

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

    <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=""/>


    The main applicationcontext is as follows

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
    name="driverClassName"><value> 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 id="JDBCTemplate"
    class="org.springframework.jdbc.core.JdbcTemplate" >
    <constructor-arg index="0"><ref bean="dataSource" /></constructor-arg>

    and the web.xml is as follows

    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>


    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?