如何在春季3.0中component-scan
?对于jar和项目,我使用@Service,@ RTonsity等注释。这是行不通的。当项目中的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)
答案 0 :(得分:0)
仅限<context:component-scan base-package="com.java.spring.support, org.me.project">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
使用。
答案 1 :(得分:0)
<context:component-scan base-package="org.me.project"/>
您正在对存储库注释使用排除过滤器,将其删除。