Announcement Announcement Module
Collapse
No announcement yet.
Problem with Component-Scan in dependend JAR-File. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with Component-Scan in dependend JAR-File.

    Hello friends,

    I have a GWT-Application split in 2 eclipse-projects, both being managed by Maven 2.2 and the m2eclipse-Plugin 0.12.

    P1: Web-Application-Project (-> .war)
    P2: Simple Java Project (->.jar).

    P1 references P2 through a Maven-Dependency which all seems to work fine.

    So my problem is as follows:

    P1 declares a Dispatcher-Servlet "spring-web" in web.xml:

    HTML Code:
      <servlet>
    	<servlet-name>spring-web</servlet-name>
    	<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
      </servlet>
    Because of this declaration Spring is going to consume my following configuration-file "spring-web-servlet.xml" which looks as follows:

    HTML Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans>
    
       	<context:component-scan base-package="wwi.server.action" />
    
    	<bean id="commandService" class="de.wwag.common.ui.gwt.command.server.SpringCommandServiceServlet" />
    	
    	<!-- no 'id' required, HandlerMapping beans are automatically detected by the DispatcherServlet -->
    	<bean class="de.wwag.common.ui.gwt.command.server.handler.GWTRPCHandlerMapping">
    	  <property name="mappings">
    	    <map>
    	      <entry key="/GwtApp/command" value-ref="commandService" />
    	    </map>
    	  </property>
    	</bean>
    SpringCommandServiceServlet should create Beans from some @Component-annotated Classes that are placed in P2 (Package "wwi.server.action"). Therefore I want to use the component-scanning Feature in this spring-configuration. Sadly, the Beans are not being created by Spring.

    When initalizing the Spring-Context I see the following Log-Statement:
    2012-02-10 16:54:39,968 DEBUG [btpool0-0] [-721bc142:13567f915a7:-7ffe] support.PathMatchingResourcePatternResolver (PathMatchingResourcePatternResolver.java:353) - Resolved location pattern [classpath*:wwi/server/action/**/*.class] to resources []
    When building the final war-File everything works fine. Only when using the "Run as Webapplication" the component-scan does absolutely nothing

    I've also looked in the resultating WAR- and JAR-Files which all looked as expected.

    What kind of problem could that be? Some kind of classloader problem?
    Any experiences or tips solving this strange behaviour?

  • #2
    I am not sure I understand your query, but I am assuming that spring is unable to scan classes marked as @component which are present in the jar file. The way we have done this is that we have a applicationContext file as part P2 project(jar) which scan for the classes present in it. We import that config in our web project using classpath* which looks for files in jar also.

    Hope this helps

    Comment

    Working...
    X