component-scan
spring 3.0 怎么办?我对 jar 和项目都使用 @Service、@Reponsity 等注释。这没用。当项目中的bean从jar中的bean注入时。
在 jar 文件中
com.java.spring.support
在项目中
org.me.project
我的配置是
<context:annotation-config/>
<context:component-scan base-package="com.java.spring.support, org.me.project"/>
在 Jar 文件中
package com.java.spring.support;
@Service("CommonService")
public class CommonService {
}
在项目中
package org.me.project;
@Service(value = "OtherService")
public class OtherService {
@Resource(name = "CommonService")
private CommonService service;
}
我收到错误
15:41:53,043 DEBUG [org.springframework.context.support.ClassPathXmlApplicationContext] Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.sprin
gframework.context.support.DefaultLifecycleProcessor@510ebe18]
15:41:53,044 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] Returning cached instance of singleton bean 'lifecycleProcessor'
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'CommonService' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093)
at org.ace.java.support.delete.Test.main(Test.java:13)