Skip to content

Commit 7d63587

Browse files
committed
Samples refactor and new docs for samples
1 parent 4c04f79 commit 7d63587

16 files changed

+187
-477
lines changed

src/main/java/org/mybatis/spring/mapper/ClassPathMapperScanner.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class ClassPathMapperScanner extends ClassPathBeanDefinitionScanner {
7070

7171
private Class<?> markerInterface;
7272

73-
private MapperFactoryBean mapperFactoryBean = new MapperFactoryBean();
73+
private MapperFactoryBean<?> mapperFactoryBean = new MapperFactoryBean<Object>();
7474

7575
public ClassPathMapperScanner(BeanDefinitionRegistry registry) {
7676
super(registry, false);
@@ -104,8 +104,8 @@ public void setSqlSessionFactoryBeanName(String sqlSessionFactoryBeanName) {
104104
this.sqlSessionFactoryBeanName = sqlSessionFactoryBeanName;
105105
}
106106

107-
public void setMapperFactoryBean(MapperFactoryBean mapperFactoryBean) {
108-
this.mapperFactoryBean = mapperFactoryBean != null ? mapperFactoryBean : new MapperFactoryBean();
107+
public void setMapperFactoryBean(MapperFactoryBean<?> mapperFactoryBean) {
108+
this.mapperFactoryBean = mapperFactoryBean != null ? mapperFactoryBean : new MapperFactoryBean<Object>();
109109
}
110110

111111

src/main/java/org/mybatis/spring/mapper/MapperFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class MapperFactoryBean<T> extends SqlSessionDaoSupport implements Factor
5959
private boolean addToConfig = true;
6060

6161
public MapperFactoryBean() {
62-
//intentially empty
62+
//intentionally empty
6363
}
6464

6565
public MapperFactoryBean(Class<T> mapperInterface) {

src/site/xdoc/sample.xml

Lines changed: 147 additions & 435 deletions
Large diffs are not rendered by default.

src/test/java/org/mybatis/spring/sample/ConfigurationSampleTest.java renamed to src/test/java/org/mybatis/spring/sample/SampleConfigurationTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import org.mybatis.spring.SqlSessionFactoryBean;
3030
import org.mybatis.spring.SqlSessionTemplate;
3131
import org.mybatis.spring.mapper.MapperFactoryBean;
32-
import org.mybatis.spring.sample.dao.UserDao;
3332
import org.mybatis.spring.sample.domain.User;
33+
import org.mybatis.spring.sample.mapper.UserMapper;
3434
import org.mybatis.spring.sample.service.FooService;
3535
import org.springframework.beans.factory.annotation.Autowired;
3636
import org.springframework.context.annotation.Bean;
@@ -47,7 +47,7 @@
4747

4848
@RunWith(SpringJUnit4ClassRunner.class)
4949
@ContextConfiguration(loader = AnnotationConfigContextLoader.class)
50-
public class ConfigurationSampleTest {
50+
public class SampleConfigurationTest {
5151

5252
@Configuration
5353
static class ContextConfiguration {
@@ -70,21 +70,21 @@ public PlatformTransactionManager transactionalManagerOne() {
7070
public SqlSessionFactory sqlSessionFactory() throws Exception {
7171
SqlSessionFactoryBean ss = new SqlSessionFactoryBean();
7272
ss.setDataSource(dataSource());
73-
ss.setMapperLocations(new Resource[] { new ClassPathResource("org/mybatis/spring/sample/dao/UserDao.xml") });
73+
ss.setMapperLocations(new Resource[] { new ClassPathResource("org/mybatis/spring/sample/mapper/UserMapper.xml") });
7474
return (SqlSessionFactory) ss.getObject();
7575
}
7676

7777
@Bean
78-
public UserDao userDao() throws Exception {
78+
public UserMapper userMapper() throws Exception {
7979
// when using javaconfig a template requires less lines than a MapperFactoryBean
8080
SqlSessionTemplate sessionTemplate = new SqlSessionTemplate(sqlSessionFactory());
81-
return sessionTemplate.getMapper(UserDao.class);
81+
return sessionTemplate.getMapper(UserMapper.class);
8282
}
8383

8484
@Bean
85-
public UserDao userDaoWithFactory() throws Exception {
86-
MapperFactoryBean<UserDao> mapperFactoryBean = new MapperFactoryBean<UserDao>();
87-
mapperFactoryBean.setMapperInterface(UserDao.class);
85+
public UserMapper userMapperWithFactory() throws Exception {
86+
MapperFactoryBean<UserMapper> mapperFactoryBean = new MapperFactoryBean<UserMapper>();
87+
mapperFactoryBean.setMapperInterface(UserMapper.class);
8888
mapperFactoryBean.setSqlSessionFactory(sqlSessionFactory());
8989
mapperFactoryBean.afterPropertiesSet();
9090
return mapperFactoryBean.getObject();
@@ -93,7 +93,7 @@ public UserDao userDaoWithFactory() throws Exception {
9393
@Bean
9494
public FooService fooService() throws Exception {
9595
FooService fooService = new FooService();
96-
fooService.setUserDao(userDao());
96+
fooService.setUserMapper(userMapper());
9797
return fooService;
9898
}
9999
}

src/test/java/org/mybatis/spring/sample/SampleEnableTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class SampleEnableTest extends AbstractSampleTest {
3232

3333
@Configuration
3434
@ImportResource("classpath:org/mybatis/spring/sample/config/applicationContext-infrastructure.xml")
35-
@MapperScan("org.mybatis.spring.sample.dao")
35+
@MapperScan("org.mybatis.spring.sample.mapper")
3636
static class AppConfig {
3737
}
3838
}

src/test/java/org/mybatis/spring/sample/config/applicationContext-batch.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
<import resource="classpath:org/mybatis/spring/sample/config/applicationContext-infrastructure.xml"/>
3030

3131
<!-- To change the default ExecutorType, a custom SqlSessionTemplate is all that is needed. -->
32-
<bean id="userDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
33-
<property name="mapperInterface" value="org.mybatis.spring.sample.dao.UserDao" />
32+
<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
33+
<property name="mapperInterface" value="org.mybatis.spring.sample.mapper.UserMapper" />
3434
<property name="sqlSessionTemplate">
3535
<bean class="org.mybatis.spring.SqlSessionTemplate">
3636
<constructor-arg index="0" ref="sqlSessionFactory" />

src/test/java/org/mybatis/spring/sample/config/applicationContext-infrastructure.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@
5656
file. This config file could, in turn, contain &ltmapper&gt
5757
elements that point to the correct mapper xml files.
5858
-->
59-
<property name="mapperLocations" value="classpath:org/mybatis/spring/sample/dao/*.xml" />
59+
<property name="mapperLocations" value="classpath:org/mybatis/spring/sample/mapper/*.xml" />
6060
</bean>
6161

62-
<!-- simple transactional service layer bean; the userDao can be implemented in various ways with MyBatis-Spring -->
62+
<!-- simple transactional service layer bean; MyBatis-Spring will create a proxy for the userMapper bean -->
6363
<bean id="fooService" class="org.mybatis.spring.sample.service.FooService">
64-
<property name="userDao" ref="userDao" />
64+
<property name="userMapper" ref="userMapper" />
6565
</bean>
6666
</beans>

src/test/java/org/mybatis/spring/sample/config/applicationContext-mapper.xml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
<!--
1919
A sample context that shows how to integrate MyBatis with Spring using a
20-
MapperFactoryBean. With this configuration, DAOs are created
20+
MapperFactoryBean. With this configuration, mappers are created
2121
automatically but each one much be defined in the context using an
2222
implementation (mapper) interface.
2323
@@ -31,10 +31,8 @@
3131
<!-- import datasource and transaction manager -->
3232
<import resource="classpath:org/mybatis/spring/sample/config/applicationContext-infrastructure.xml" />
3333

34-
<!-- Directly injecting mappers; notice there is no UserDaoImplementation
35-
needed, but the DAO interface is required. The required SqlSessionFactory
36-
will be autowired. -->
37-
<bean id="userDao" class="org.mybatis.spring.mapper.MapperFactoryBean" autowire="byType">
38-
<property name="mapperInterface" value="org.mybatis.spring.sample.dao.UserDao" />
34+
<!-- Directly injecting mappers. The required SqlSessionFactory will be autowired. -->
35+
<bean id="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean" autowire="byType">
36+
<property name="mapperInterface" value="org.mybatis.spring.sample.mapper.UserMapper" />
3937
</bean>
4038
</beans>

src/test/java/org/mybatis/spring/sample/config/applicationContext-namespace.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
<!-- Scan for mappers and let them be autowired; notice there is no
3636
UserDaoImplementation needed. The required SqlSessionFactory will be
3737
autowired. -->
38-
<mybatis:scan base-package="org.mybatis.spring.sample.dao" />
38+
<mybatis:scan base-package="org.mybatis.spring.sample.mapper" />
3939
</beans>

src/test/java/org/mybatis/spring/sample/config/applicationContext-scanner.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
UserDaoImplementation needed. The required SqlSessionFactory will be
3535
autowired. -->
3636
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
37-
<property name="basePackage" value="org.mybatis.spring.sample.dao" />
37+
<property name="basePackage" value="org.mybatis.spring.sample.mapper" />
3838
</bean>
3939
</beans>

0 commit comments

Comments
 (0)