Tôi có mã @Inject
hoạt động trong một lớp nhưng không hoạt động ở một lớp khác. Dưới đây là mã của tôi:Chú thích mùa xuân @Inject không hoạt động
- context.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
lớp hiện diện trong com.myfashions.dao
gói. @Inject
không hoạt động trong Seller.java. Có lý do gì không?
Lớp học Người bán có được quản lý không? Hay bạn đang tạo nó với toán tử 'new'? –
Cảm ơn @ nicholas.hauschild u khiến tôi biết sai lầm của mình. Tôi đã tạo đối tượng đó với toán tử mới. Vì vậy, đó là lý do tôi nhận được tất cả các tiêm null – vicky
'@ Inject' không phải là một chú thích mùa xuân – ACV