Announcement Announcement Module
Collapse
No announcement yet.
Context scanning doesn't seem to work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Context scanning doesn't seem to work

    I'm getting the following:
    Code:
    2013-03-27 18:51:54,944 ERROR    pringframework.web.context.ContextLoader: 227 - Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'exporter' defined in URL ... Cannot resolve reference to bean 'dynamicNamingStrategy' while setting bean property 'namingStrategy'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'dynamicNamingStrategy' is defined
    	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    	at
    and also STS is complaining:
    Code:
    Multiple annotations found at this line:
    	- Referenced bean 'dynamicNamingStrategy' 
    	 not found
    with the following Spring contexts setup:

    In a project, I have a jmx management context (core-app-web-common-management-context.xml) with following (excerpt):

    Code:
    	<context:annotation-config />
    
    	<context:component-scan
    		base-package="com.a.b.c.management.*" />
    
    
    	<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"
    		lazy-init="false">
    		<property name="autodetect" value="true"></property>
    		<property name="namingStrategy" ref="dynamicNamingStrategy"/>
    where dynamicNamingStrategy is defined in a different project (and packaged into a different jar) and is referred to in the component-scan above, as follows

    Code:
    package com.a.b.c.management;
    
    
    @Component("dynamicNamingStrategy")
    public class DynamicNamingStrategy extends KeyNamingStrategy {
    ......
    The above Spring context is in turn imported into the main context located in the same project:

    Code:
    <import resource="classpath*:/META-INF/spring/core-app-web-common-management-context.xml"/>
    So, somehow the @Component scanning for DynamicNamingStrategy is not working...

    If I instead use this property definition in exporter, then it works:

    Code:
    <property name="namingStrategy"><bean class="com.a.b.c.management.DynamicNamingStrategy" /></property>
    but I'd like to understand why the component scanning mechanism falters in the first instance, apparently I'm missing something.

    Also, Spring Explorer view in STS is missing that bean as well. Enabling support for <import> elements in configuration files option doesn't seem to make a difference.

    Thank you in advance.
    Simeon

  • #2
    Hi, Simeon.

    Is it different if you change following configuration

    <context:component-scan base-package="com.a.b.c.management.*" />

    into following code?

    <context:component-scan base-package="com.a.b.c.management" />

    In my testcase, It seems work differently.

    Comment


    • #3
      No, it's not. In my case it doesn't matter.

      Comment

      Working...
      X