我是新学科
我有配置
并尝试注入它
@Controller
public class HelloController {
@Autowired
HibernateTemplate hibernateTemplate;
@RequestMapping(value = "/hello.htm", method = RequestMethod.GET)
public @ResponseBody String save() throws Exception {
hibernateTemplate.save(new Some(Long.valueOf("33"), Integer.valueOf("1"), Double.valueOf("1"), Short.valueOf("0")));
}
}
这行得通。
但是如果我尝试在其他类中使用 @Autowired 我有 NPE 示例
public class SomeFacade extends AbstractFacade<Some> {
@Autowired
HibernateTemplate hibernateTemplate;
@Override
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
}
并将其用于
@Controller
public class HelloController {
@RequestMapping(value = "/hello.htm", method = RequestMethod.GET)
public @ResponseBody String save() throws Exception {
SomeFacade df = new SomeFacade();
HibernateTemplate ht = df.getHibernateTemplate();
}
}
我有“ht”是空的
我不知道该代码中发生了什么以及为什么它不起作用,我认为这是因为我的类没有在 xml 文件中注册。请帮助这个例子。谢谢你!