Spring-----Mybatis-通过Sqlsessionsupport
org.springframework.context.support.AbstractApplicationContext refresh
警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userdaoimpl' defined in class path resource [applicationcontext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userdaoimpl' defined in class path resource [applicationcontext.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required
1.
<bean id="userdaoimpl" class="com.sun.dao.UserDaoImpl" > <property name="sqlSessionFactory" ref="sqlsessionfactorybean"/> //继承的抽象类传入的参数(注入)在子类中注入。
<!-- <property name="sessionTemplate" ref="sqlsession"/>--> </bean>
public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao { // private SqlSessionTemplate sessionTemplate; @Override public List<User> getUserList() { // List<User> userList = sessionTemplate.selectList("com.sun.dao.UserDao.getUserList"); UserDao mapper = getSqlSession().getMapper(UserDao.class); //SqlsessionTemplate ===getSqlSession() List<User> userList = mapper.getUserList(); return userList; } // public void setSessionTemplate(SqlSessionTemplate sessionTemplate) { // this.sessionTemplate=sessionTemplate; // } }