Announcement Announcement Module
Collapse
No announcement yet.
Spring JAR configuration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring JAR configuration

    Hi,

    first I'd like to apologize, but I'm quite new to Spring, specially configuring projects from the beginning, so maybe this will be really trivial question.

    I'd like to separate my data layer as a separate maven project and use it as a dependency in other web projects. I'd like to know how do I have to setup application context.xml, to load my Spring configuration, so that I'll be able to use this JAR just as a dependency in another project(s).

    I know application context has to reside within classpath, so my resist in resources/META-INF together with persistance.xml file.

    I'd be gratefull if somebody could let me know what are the next steps or point me to some good sample.

    Another question is, what is the easiest way to unit test this application?

    Thanks in advance.

    Gregor

  • #2
    You can separate projects and have your spring application-context.xml in the main project import the application context in the dependency as follows.

    <?xml version="1.0" encoding="UTF-8"?>

    Code:
    <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    	                    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
    
    	<import resource="classpath:spring/core-context.xml" />
    
    </beans>
    In your build tool you can add the dependency in your config e.g. if you are using maven you can add it like ..

    <dependency>
    <groupId>com.base.dependency</groupId>
    <artifactId>dependency</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    </dependency>

    As for your other question regarding Unit testing, there should be no change in the way you do unit tests. Unit test only test the particular unit of code and are not dependent on architctural changes. Integration test on the other hand would test the flow of the system. For that, you need to check the spring test framework.

    Originally posted by gregamb View Post
    Hi,

    first I'd like to apologize, but I'm quite new to Spring, specially configuring projects from the beginning, so maybe this will be really trivial question.

    I'd like to separate my data layer as a separate maven project and use it as a dependency in other web projects. I'd like to know how do I have to setup application context.xml, to load my Spring configuration, so that I'll be able to use this JAR just as a dependency in another project(s).

    I know application context has to reside within classpath, so my resist in resources/META-INF together with persistance.xml file.

    I'd be gratefull if somebody could let me know what are the next steps or point me to some good sample.

    Another question is, what is the easiest way to unit test this application?

    Thanks in advance.

    Gregor

    Comment


    • #3
      I want to do something similar (if not the same) as gregamb. I have some classes in one web app project that will be needed by several other web apps running in the same servlet container. So my plan was to move those classes into a new project, whose jar file would go in Tomcat's shared lib directory. Do I understand correctly, then, that I should include an applicationContext.xml in that jar file and import the shared jar's applicationContext.xml in the applicationContext.xml of all the apps that use the shared jar, as shown above?

      Comment

      Working...
      X