私はコード@Inject
を持っていますが、他のクラスでは動作しません。春の注釈@Injectは機能しません
- のcontext.xml
public class SellerRetriever {
@Inject
UserDAO userDAO;
...
...
}
UserDAO
クラスがcom.myfashions.dao
パッケージ内に存在している
<?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: はここに私のコードです。
@Inject
がSeller.javaで動作していません。理由は何ですか?
'Seller'クラスはSpringで管理されていますか?あるいは、 'new'演算子でそれを作成していますか? –
ありがとう@ nicholas.hauschild私は私の間違いを知った。私は新しい演算子でそのオブジェクトを作成しました。だから私はすべてのインジェクションを取得した理由はnullです – vicky
'@ Inject'は春の注釈ではありません – ACV