Skip to content

Commit 23d3b55

Browse files
committed
if the only way to set the sqlSessionFactory is through the ctor, sqlSessionFactory can be final and the assertion must be verified before setting the field reference
1 parent 658e384 commit 23d3b55

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

src/main/java/org/mybatis/spring/SqlSessionTemplate.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@
7575
*/
7676
public class SqlSessionTemplate extends JdbcAccessor implements SqlSessionOperations {
7777

78-
private SqlSessionFactory sqlSessionFactory;
78+
private final SqlSessionFactory sqlSessionFactory;
7979

8080
public SqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
81+
Assert.notNull(sqlSessionFactory, "Property 'sqlSessionFactory' is required");
8182
this.sqlSessionFactory = sqlSessionFactory;
82-
afterPropertiesSet();
8383
}
8484

8585
public SqlSessionFactory getSqlSessionFactory() {
@@ -102,15 +102,6 @@ public DataSource getDataSource() {
102102
return this.sqlSessionFactory.getConfiguration().getEnvironment().getDataSource();
103103
}
104104

105-
/**
106-
* {@inheritDoc}
107-
*/
108-
@Override
109-
public void afterPropertiesSet() {
110-
Assert.notNull(this.sqlSessionFactory, "Property 'sqlSessionFactory' is required");
111-
super.afterPropertiesSet();
112-
}
113-
114105
/**
115106
* Execute the given data access action with the proper SqlSession (got from current transaction or
116107
* a new one)
@@ -216,7 +207,7 @@ public List<T> doInSqlSession(SqlSession sqlSession) {
216207
// }
217208
// });
218209
// }
219-
210+
220211
/**
221212
* {@inheritDoc}
222213
*/

0 commit comments

Comments
 (0)