|
55 | 55 | import org.mybatis.spring.transaction.SpringManagedTransactionFactory; |
56 | 56 | import org.springframework.beans.factory.FactoryBean; |
57 | 57 | import org.springframework.beans.factory.InitializingBean; |
58 | | -import org.springframework.context.ApplicationEvent; |
59 | 58 | import org.springframework.context.ApplicationListener; |
60 | 59 | import org.springframework.context.ConfigurableApplicationContext; |
61 | 60 | import org.springframework.context.event.ContextRefreshedEvent; |
|
96 | 95 | * |
97 | 96 | * @see SqlSessionFactoryBean |
98 | 97 | */ |
99 | | -public final class MyBatisMapperSqlSessionFactoryBean implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ApplicationEvent> { |
| 98 | +public final class MyBatisMapperSqlSessionFactoryBean implements FactoryBean<SqlSessionFactory>, InitializingBean, ApplicationListener<ContextRefreshedEvent> { |
100 | 99 |
|
101 | 100 | private static final Logger LOGGER = LoggerFactory.getLogger( MyBatisMapperSqlSessionFactoryBean.class ); |
102 | 101 |
|
103 | 102 | private static final ResourcePatternResolver RESOURCE_PATTERN_RESOLVER = new PathMatchingResourcePatternResolver(); |
104 | 103 | private static final MetadataReaderFactory METADATA_READER_FACTORY = new CachingMetadataReaderFactory(); |
105 | 104 |
|
| 105 | + // Bean initialization status monitoring |
| 106 | + // Added in 1.3.2 |
| 107 | + private boolean isInitialized; |
| 108 | + |
106 | 109 | // mybatis-spring original variables |
107 | 110 |
|
108 | 111 | private Resource configLocation; |
@@ -671,8 +674,9 @@ public boolean isSingleton() { |
671 | 674 | * @since mybatis-mapper-spring 1.3.0 |
672 | 675 | */ |
673 | 676 | @Override |
674 | | - public void onApplicationEvent( ApplicationEvent event ) { |
675 | | - if ( event instanceof ContextRefreshedEvent ) { |
| 677 | + public void onApplicationEvent( ContextRefreshedEvent event ) { |
| 678 | + if ( !isInitialized ) { // Added in 1.3.2 |
| 679 | + isInitialized = true; // Prevent duplicate execution |
676 | 680 | LoggerUtil.printBootstrapLog(); |
677 | 681 | this.mybatisMapperBuilder.refactoring( sqlSessionFactory.getConfiguration() ); |
678 | 682 | LoggerUtil.printLoadedLog(); |
|
0 commit comments