spring 注入问题,获取值为null
publicinterfaceUserService{voidadd(Useruser);}@ServicepublicclassUserServiceImplimple...
public interface UserService {
void add(User user);
}
@Service
public class UserServiceImpl implements UserService {
@Resource
private UserDao userDao;
public void add(User user){
userDao.add(user);
}
}
@Controller
@Scope("prototype")
public class TestBean {
@Resource()
private UserService userService ;
@Test
public void testHibernate() throws Exception {
System.out.println("==================");
System.out.println(userService);
System.out.println("==================");
}
}
这样打印出null,没搞明白是哪里写错了吗?
applicationContext.xml就配了一个
<!-- 设置扫描路径 -->
/context:component-scan 展开
void add(User user);
}
@Service
public class UserServiceImpl implements UserService {
@Resource
private UserDao userDao;
public void add(User user){
userDao.add(user);
}
}
@Controller
@Scope("prototype")
public class TestBean {
@Resource()
private UserService userService ;
@Test
public void testHibernate() throws Exception {
System.out.println("==================");
System.out.println(userService);
System.out.println("==================");
}
}
这样打印出null,没搞明白是哪里写错了吗?
applicationContext.xml就配了一个
<!-- 设置扫描路径 -->
/context:component-scan 展开
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询