我的代码@Inject
在一个类中有效,但在其他类中无效。这是我的代码:
- 上下文.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
">
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>
<context:component-scan base-package="com.myfashions.services"/>
<context:component-scan base-package="com.myfashions.dao"/>
</beans>
- SellerRetriever.java
public class SellerRetriever {
@Inject
UserDAO userDAO;
...
...
}
UserDAO
类存在于com.myfashions.dao
包中。
@Inject
不在 Seller.java 中工作。有什么理由吗?