Code Bye

多项目中spring配置 Injection of resource dependencies failed

有两个项目,一个是inter_bh_service(只做业务方面的,打成war包放到tomcat的webapps目录下),另一个是inter_db_base(只做持久化操作,这个项目是以jar包的形式关联inter_bh_service的),
inter_bh_service的spring配置文件applicationContext-bh-service.xml部分配置如下

	<import resource="classpath:../lib/inter_db_base-0.0.1-SNAPSHOT.jar/applicationContext-dbase.xml" />
	<!-- <import resource="applicationContext-dbase.xml" /> -->
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
	<bean id="userInfoSyncBhServiceImpl" class="net.snailgame.inter.bh.service.impl.UserInfoSyncBhServiceImpl">
		<property name="userStatusServiceBh" ref="userStatusServiceBhImpl" />//问题就在这里,这是inter_db_base中的一个类
		<property name="serviceConfig" ref="serviceConfig" />
	</bean>
	 <context:component-scan base-package="net.snailgame.inter.bh.service"></context:component-scan> 
	<!-- 用户信息同步接口 -->
	<bean id="serviceConfig" class="net.snailgame.inter.bh.po.ServiceConfig">
		<property name="sourceCode" value="3" />
		<property name="version" value="01" />
	</bean>

inter_db_base的spring配置文件applicationContext_dbase.xml部分配置如下

	<context:component-scan base-package="net.snailgame.inter.service">
	</context:component-scan>
	<context:component-scan base-package="net.snailgame.inter.dao">
	</context:component-scan>

自动扫描的其中一个类如下

@Service
public class UserStatusServiceBhImpl implements UserStatusServiceBh {
    @Resource(name="tbNsBssUserInfoBhDaoImpl")
    private TbNsBssUserInfoBhDao tbNsBssUserInfoBhDao;
    @Resource(name="tbNsBssUserOrderBhDaoImpl")
    private TbNsBssUserOrderBhDao tbNsBssUserOrderBhDao;
    @Autowired
    private QSendToServerBhDao qSendToServerBhDao;
    @Autowired
    private LogUserStateChangeDao logUserStateChangeDao;
    @Autowired
    private TbNsUserLifeCycleBhDao tbNsUserLifeCycleBhDao;
    @Autowired
    private TbNsCardInfoBhDao tbNsCardInfoBhDao;
    // @Autowired
    // private QNsCardInfoBhDao qNsCardInfoBhDao;
    @Autowired
    private LogUserInfoSyncCnToBhDao logUserInfoSyncCnToBhDao;
}

在启动tomcat时,上面的属性都为空
web.xml如下

<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>WEB-INF/classes/applicationContext-bh-service.xml</param-value>
	</context-param>
	<listener> 
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

启动报错信息如下

八月 05, 2015 8:10:16 下午 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ""userInfoSyncBhServiceImpl"": Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ""userStatusServiceBhImpl"" is defined
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1106)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:607)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
	at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:943)
	at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:778)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:504)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
	at org.apache.catalina.core.StandardService.start(StandardService.java:525)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named ""userStatusServiceBhImpl"" is defined
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:549)
	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:197)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.autowireResource(CommonAnnotationBeanPostProcessor.java:442)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:416)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:550)
	at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:155)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:92)
	at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303)
	... 37 more
#1

80分

http://bbs.csdn.net/topics/390684950
这贴的三楼,jar包打包时候add directory entries这个勾选上试试看有用不
#2
路径没写入
#3
问题定位了,1楼给的链接确实能解决我的问题

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明多项目中spring配置 Injection of resource dependencies failed