版权声明:博客知识产权来源命运的信徒,切勿侵权 https://blog.csdn.net/qq_37591637/article/details/88661094
错误代码
@Autowired
private SessionFactory sf;
@Autowired
private String name;
错误原因:
@Autowired是自动装配的意思
1、如果你装配的是对象类型的如
@Autowired
private SessionFactory sf;
@Autowired
private Car c;
你要在applciationContext里面配置好
<bean name="car" class="cn.com.bean.Car">
<property name="name" ></property>
</bean>
或者是扫描包的路径包含这个对象的路径
<context:component-scan base-package="cn.com.*"></context:component-scan>
2、如果你装配的是
@Autowired
private String name;
就大错特错了,这个String是基础类型,需要提供set和get方法
我对这个自动装配不理解,以为只要是属性都可以装配!