3

I use Spring 3 in my project.Then I face a problem when I inject spring bean from JAR file. In JAR file, there is class like;

package test;

@Service("CommonService")
public class CommonService {
}

And i already used it like this;

package com.java.test.app;

@Service(value = "OtherService")
public class OtherService {
    @Resource(name = "CommonService")
    private CommonService service;
}

In my spring-beans.xml;

<context:component-scan base-package="com.java.test.app, test">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Repository"/>
</context:component-scan>

But @Resource annotation doesn't work.Can I inject spring bean from JAR file?

4

1 回答 1

0

如果在运行时您的 CommonService 类位于类路径上,并且位于您使用组件扫描指定的基本包中,那么您应该很高兴。尝试使用@Autowired 而不是@Resource。

于 2012-11-09T17:53:47.017 回答