Skip to content

Commit

Permalink
Use @value to work around a bug on @ConfigurationProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
izeye committed Nov 25, 2019
1 parent 292a2cf commit b7742a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/izeye/throwaway/config/PersistenceConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.core.io.Resource;

import javax.sql.DataSource;

Expand All @@ -24,12 +26,16 @@ public class PersistenceConfig {
@Autowired
private MyBatisProperties myBatisProperties;

// FIXME: See https://github.com/spring-projects/spring-boot/issues/15835
@Value("${mybatis.mapper-locations}")
private Resource[] mapperLocations;

@Bean
public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource) {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
sqlSessionFactoryBean.setConfigLocation(myBatisProperties.getConfigLocation());
sqlSessionFactoryBean.setMapperLocations(myBatisProperties.getMapperLocations());
sqlSessionFactoryBean.setConfigLocation(this.myBatisProperties.getConfigLocation());
sqlSessionFactoryBean.setMapperLocations(this.mapperLocations);
sqlSessionFactoryBean.setVfs(SpringBootVFS.class);
return sqlSessionFactoryBean;
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mybatis.config-location=classpath:mybatis/sqlmap-config.xml

# FIXME: Why doesn't this work?
#mybatis.mapper-locations=classpath:mybatis/mappers/*.xml
mybatis.mapper-locations=classpath:mybatis/mappers/person-repository.xml
mybatis.mapper-locations=classpath:/mybatis/mappers/*.xml

# FIXME: See https://github.com/spring-projects/spring-boot/issues/15835
#mybatis.mapper-locations=classpath:mybatis/mappers/person-repository.xml

0 comments on commit b7742a0

Please sign in to comment.