Today, when consolidating SPRINGMVC and MyBatis, the boot server encounters such a problem,
By:java.lang.IllegalArgumentException:Property ' sqlsessionfactory ' or ' sqlsessiontemplate ' is required at Org.springframework.util.Assert.notNull (assert.java:112)
An exception means a lack of sqlsessionfactory or sqlsessiontemplate.
My DAO layer is the use of inheritance sqlsessiondaosupport and then can be directly through the this.getsqlsession () to the operation of the database.
Later, by searching and viewing source code discovery, the Mybatis-spring 1.2 version did not automatically inject sqlsessionfactory
The workaround is to manually inject
1 Public class extends Sqlsessiondaosupport {2 3 @Autowired 4 Public void setsqlsessionfactory (sqlsessionfactory sqlsessionfactory) { 5 Super . Setsqlsessionfactory (sqlsessionfactory); 6 }7 }
Then, when you inherit the DAO implementation class Basedaoimpl, you can use the
1 @Repository2 Public classPersondaoimplextendsBasedaoimplImplementsPersondao {3 4String ns = "Cn.tx.mapper.PersonMapper.";5 @Override6 Public voidSaveperson (person p) {7 This. getsqlsession (). Insert (ns+ "Saveperson", p);8 }9 Ten @Override One PublicPerson Selectpersonbyid (Integer personId) { A return This. Getsqlsession (). SelectOne (ns+ "Selectpersonbyid", personId); - } - the @Override - Public voidUpdate (person p) { - This. Getsqlsession (). Update (ns + "Update", p); - } + - @Override + Public voidDelete (Integer personId) { A This. Getsqlsession (). Delete (ns + "Delete", personId); at } - - @Override - PublicList<person>selectpersonbycondition (Querycondition QC) { - return This. Getsqlsession (). SelectList (ns + "selectpersonbycondition"), QC); - } in -}
SPRINGMVC and MyBatis Integration Java.lang.IllegalArgumentException:Property ' sqlsessionfactory ' or ' sqlsessiontemplate ' are Required exception