Announcement Announcement Module
Collapse
No announcement yet.
Issues in loading bean by autoscanning Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issues in loading bean by autoscanning

    Hi there.

    I'm using this environment:
    • Eclipse Indigo
    • Maven 3.0.4
    • GWT 2.4.0
    • GWT-dispatch 1.2.0
    • Spring 3.1.1
    • JVM 1.6

    Here there is my web.xml file:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app..>
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    		    classpath:spring-gwtDispatch-context.xml,
    			classpath:spring-application-context.xml
    		</param-value>
    	</context-param>
    	<context-param>
    		<param-name>log4jConfigLocation</param-name>
    		<param-value>/WEB-INF/classes/log4j.xml</param-value>
    	</context-param>
    	<listener>
    		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    	</listener>    
      	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	<servlet>
    		<servlet-name>dispatch</servlet-name>
    		<servlet-class>x.y.server.gwt.dispatch.spring.SpringStandardDispatchServlet</servlet-class>
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>dispatch</servlet-name>
    		<url-pattern>/test/dispatch</url-pattern>
    	</servlet-mapping>
    	<welcome-file-list>
    		<welcome-file>Test.html</welcome-file>
    	</welcome-file-list>
    </web-app>
    The first issue I have is that when I write the xml files one by one spring container is able in reading them. But previously (in application without using GWT) in the web.xml I could write also:
    Code:
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>
    		    classpath:spring-*-context.xml
    		</param-value>
    	</context-param>
    In this case the spring container was able in reading all xml files whose names started with spring and finished with context. Now if i write as I showed the ContextListener seems to search for the only one file the one called "spring-*-context.xml"
    Content of spring-gwtDispatch-context.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans ... >
        <context:annotation-config />
     	<context:component-scan base-package="x.y.commoncore.al.server" />
    </beans>
    Content of spring-application-context.xml
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans....>
     <context:annotation-config />
     <context:component-scan base-package="x.y.server" />
     <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" >
      <property name="locations" value="classpath:configuration.properties" />
     </bean>
     <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" depends-on="org.h2.tools.Server" destroy-method="close" >
      <property name="driverClassName" value="${DB_DRIVER_CLASS_NAME}" />
      <property name="url" value="${DB_URL}" />
      <property name="username" value="${DB_USERNAME}" />
      <property name="password" value="${DB_PASSWORD}" />
      <property name="initialSize" value="${DB_POOL_INITIAL_SIZE}" />
      <property name="maxActive" value="${DB_POOL_MAX_ACTIVE_CONNECTIONS}" />
      <property name="minIdle" value="${DB_POOL_MIN_IDLE}" />
      <property name="timeBetweenEvictionRunsMillis" value="${DB_POOL_TIME_BETWEEN_EVITIONS}" />
      <property name="validationQuery" value="${DB_POOL_VALIDATION_QUERY}" />
     </bean>
     <bean id="org.h2.tools.Server" class="org.h2.tools.Server" depends-on="org.h2.tools.Server-WebServer" destroy-method="stop" factory-method="createTcpServer" init-method="start" scope="singleton" >
      <constructor-arg value="${DB_H2_TOOLS_SERVER_CONSTRUCTOR_STRING}" />
     </bean>
     <bean id="org.h2.tools.Server-WebServer" class="org.h2.tools.Server" destroy-method="stop" factory-method="createWebServer" init-method="start" scope="singleton" >
      <constructor-arg value="${DB_H2_TOOLS_SERVER_WEB_SERVER_CONSTRUCTOR_STRING}" />
     </bean>
     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
      <property name="dataSource" ref="dataSource" />
     </bean>
     <bean id="productDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
      <property name="mapperInterface" value="it.poste.crs.invimall.server.mapper.InViMallSampleProductDao" />
      <property name="sqlSessionFactory" ref="sqlSessionFactory" />
     </bean>
    </beans>
    Note that both spring-application-context.xml and spring-gwtDispatch-context.xml are inside in two different eclipse maven project (at the end 2 different jars)

    When I launch the GWT project by using the GWT Eclipse plugin it seems to me that the container is not able in scanning the beans listed in file "spring-gwtDispatch-context.xml" while it's able in scanning beans listed in the other file.
    On other side I built a simple unit test. This is its code:
    Code:
    public class BeanScanTest {
    	@Test
    	public void springBeanScannTest(){
    		try {
    			String[] ctxNames = {"spring-gwtDispatch-context.xml","spring-application-context.xml"};
    			ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ctxNames);
    		} catch (Exception e) {
    			
    			e.printStackTrace();
    		}
    	}
    }
    In this case the bean scan is OK. In fact I can read the following in the log file:
    Code:
    10:36:40,404 INFO  [ClassPathBeanDefinitionScanner] JSR-330 'javax.inject.Named' annotation found and supported for component scanning
    10:36:40,411 DEBUG [PathMatchingResourcePatternResolver] Looking for matching resources in directory tree [/dati/workspaces/indigo/workspace/CommonCore/target/classes/x/y/commoncore/al/server]
    10:36:40,411 DEBUG [PathMatchingResourcePatternResolver] Searching directory [/dati/workspaces/indigo/workspace/CommonCore/target/classes/x/y/commoncore/al/server] for files matching pattern [/dati/workspaces/indigo/workspace/CommonCore/target/classes/x/y/commoncore/al/server/**/*.class]
    10:36:40,418 DEBUG [PathMatchingResourcePatternResolver] Resolved location pattern [classpath*:it/poste/crs/invimall/commoncore/al/server/**/*.class] to resources [file [/dati/workspaces/indigo/workspace/CommonCore/target/classes/x/y/commoncore/al/server/SpringActionHandlerBean.class], file [/dati/workspaces/indigo/workspace/CommonCore/target/classes/x/y/commoncore/al/server/SpringDispatchBean.class], file [/dati/workspaces/indigo/workspace/CommonCore/target/classes/x/y/commoncore/al/server/SpringActionHandlerRegistryBean.class]]
    10:36:40,446 DEBUG [ClassPathBeanDefinitionScanner] Ignored because not a concrete top-level class: file [/dati/workspaces/indigo/workspace/CommonCore/target/classes/x/y/commoncore/al/server/SpringActionHandlerBean.class]
    10:36:40,454 DEBUG [ClassPathBeanDefinitionScanner] Identified candidate component class: file [/dati/workspaces/indigo/workspace/CommonCore/target/classes/x/y/commoncore/al/server/SpringDispatchBean.class]
    10:36:40,455 DEBUG [ClassPathBeanDefinitionScanner] Identified candidate component class: file [/dati/workspaces/indigo/workspace/CommonCore/target/classes/x/y/commoncore/al/server/SpringActionHandlerRegistryBean.class]
    10:36:40,459 DEBUG [XmlBeanDefinitionReader] Loaded 6 bean definitions from location pattern [spring-gwtDispatch-context.xml]
    When I launch the web application I see:
    Code:
    10:42:44,543 INFO  [ClassPathBeanDefinitionScanner] JSR-330 'javax.inject.Named' annotation found and supported for component scanning
    10:42:44,546 DEBUG [PathMatchingResourcePatternResolver] Resolved location pattern [classpath*:x/y/commoncore/al/server/**/*.class] to resources []
    10:42:44,546 DEBUG [XmlBeanDefinitionReader] Loaded 4 bean definitions from location pattern [classpath:spring-gwtDispatch-context.xml]
    As you can see the loaded bean number is different. Can anybody suggest to me why this is happening? I'm fighting with this issue from 3 days
    I'm not able in understanding if it's a spring container issue, GWT issue (note that GWT plugin starts by using jetty servlet container) or, more probably, a my issue.

    Thank you
    Angelo
    Last edited by angeloimm; Aug 24th, 2012, 04:37 AM.

  • #2
    Any suggestion in doing some other tests?
    I'm fighting with this issue

    Comment


    • #3
      No idea about what kind of test I can do?
      It's really frustating

      Comment


      • #4
        Hi all
        I solved the issue...at least it seems
        The problem seems to be related to the Maven eclipse plug-in; in fact by disabling the workspace resolution property in the Web application project all worked good

        Angelo

        Comment


        • #5
          Hello there

          I know i solved as i said yesterday...but by removing the workspace resolution option means that every time i change something on other maven projects i need to run the "mvn clean install" command and this makes me be little bit slow....
          Do you have any idea on how i can solve this issue?

          Thank you
          Angelo

          Comment

          Working...
          X