在服务实施中,在@Autowired
的帮助下,我正在注入CollectInfo
对象在serviceImpl中,但我得到NullPointerException
。@Autowired春季不工作集成
package net.group.cts.service.serviceImpl;
@Service
public class EmployeeImpl implements EmployeeService {
@Autowired
CollectInfo info;
public void processData(){
info.getName();
}
}
package net.group.cts.model;
@Component
public class CollectInfo (){
String name;
public String getName(){
name = name + "Mr.";
return name;}
}
}
Xmlconfig.xml
<context:annotation-config/>
<context:component-scan base-package="net.group.cts"/>
<bean id="info" class="net.group.emp.model.CollectInfo "/>
如果您使用@Component注释了类,那么您可以共享CollectInfo class.check吗 –
是否'EmployeeImpl'弹簧容器被管理? –
@Vikram是我定义了 – Doss