Announcement Announcement Module
Collapse
No announcement yet.
Error registering bean with name '' Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error registering bean with name ''

    Hi all. I am fairly new to Spring, mostly relying on the Spring in Action book to get started. I followed a design that uses a BeanNameAutoProxyCreator (pp. 124-6 for those with the book). I am trying to get cross-cutting logging working, but I get the subject error and don't see what it's referring to. Files included below. Any help would be greatly appreciated...Mark

    --- applicationContext-services.xml (portion) ---
    <!-- =============== Logging advice ==================== -->
    <!-- this pointcut will apply to any method of any Class that ends with “Manager”
    (i.e. all service layer classes) -->
    <bean id="methodLoggingInterceptor" name="methodLoggingInterceptor" class="com.labcorp.cels.pla.common.logging.MethodL oggingInterceptor"/>
    <bean id="methodLoggingProxyCreator" name="methodLoggingProxyCreator" class="org.springframework.aop.framework.autoproxy .BeanNameAutoProxyCreator"/>
    <bean>
    <property name="beanNames">
    <list>
    <value>*Manager</value>
    </list>
    </property>
    <property name="interceptorNames">
    <value>methodLoggingInterceptor</value>
    </property>
    </bean>

    --- MethodLoggingInterceptor ---
    /**
    *
    */
    package com.labcorp.cels.pla.common.logging;

    import org.aopalliance.intercept.MethodInterceptor;
    import org.aopalliance.intercept.MethodInvocation;
    import org.apache.log4j.Level;
    import org.apache.log4j.Logger;

    /**
    *
    * @author lorenzm
    */
    public class MethodLoggingInterceptor implements MethodInterceptor {

    private static Logger log = Logger.getLogger("pla-service");

    /**
    * Constructor
    */
    public MethodLoggingInterceptor() {
    // nothing to do on construction...
    }

    /* (non-Javadoc)
    * @see org.aopalliance.intercept.MethodInterceptor#invoke (org.aopalliance.intercept.MethodInvocation)
    */
    public Object invoke(MethodInvocation invocation) throws Throwable {
    if( log.isEnabledFor(Level.INFO) ) {
    StringBuffer sb = new StringBuffer(invocation.getClass() + "." + invocation.getMethod()
    + " called with: [");
    Object[] args = invocation.getArguments();
    for(int i = 0; i < invocation.getArguments().length; i++) {
    Object o = args[i];
    sb.append(o);
    sb.append((i == args.length - 1) ? "]" : ", ");
    }
    log.info(sb);
    }
    return invocation.proceed();
    }

    }

    ---- Console -----
    ERROR [main] (ContextLoader.java:205) - Context initialization failed
    org.springframework.beans.factory.BeanDefinitionSt oreException:
    Unexpected exception parsing XML document from class path resource [applicationContext-services.xml];
    nested exception is org.springframework.beans.factory.BeanDefinitionSt oreException: Error registering bean with name '' defined in class path resource [applicationContext-services.xml]: Unnamed bean definition specifies neither 'class' nor 'parent' nor 'factory-bean' - can't generate bean name
    Last edited by lorenzm; Aug 4th, 2006, 02:26 PM. Reason: tried to keep formatting

  • #2
    Looks like a bug in your app context

    You split up a critical bean into two. The second one had no "id" tag, and confused Spring. I can't testify to the wildcard you have inside "beanNames", because I don't use any.

    (Slightly corrected):
    Code:
    <!-- =============== Logging advice ==================== -->
    <!-- this pointcut will apply to any method of any Class that ends with “Manager” 
    (i.e. all service layer classes) -->
    <bean id="methodLoggingInterceptor" name="methodLoggingInterceptor" class="com.labcorp.cels.pla.common.logging.MethodL oggingInterceptor"/>
    <bean id="methodLoggingProxyCreator" name="methodLoggingProxyCreator" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
        <property name="beanNames">
        <list>
            <value>*Manager</value>
        </list>
        </property>
        <property name="interceptorNames">
            <list>
                <value>methodLoggingInterceptor</value>
            </list>
        </property>
    </bean>
    Here is one that I have that works great for me. All of this is one big bean (with references to other sub-beans).

    Code:
    	<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    		<property name="beanNames">
    			<value>dataAccess</value>
    		</property>
    		<property name="interceptorNames">
    			<list>
    				<value>security</value>
    				<value>gettersPerformanceAdvisor</value>
    				<value>gettersDataFilterAdvisor</value>
    			</list>
    		</property>
    	</bean>

    Comment

    Working...
    X