SpringBoot integration with mybatis service startup exception log
2019-09-18 19:52:17.270 WARN 8320 — [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization – cancelling refresh attempt: org.springframework.beans.factory. BeanCreationException: Error creating bean with name ‘testDtoMapper’ defined in file [D:\workspace\xesWorkspace\xes\target\classes\com\xes\www\core\mapper\TestDtoMapper. class]: Cannot resolve reference to bean ‘sqlSessionFactoryBean’ while setting bean property ‘sqlSessionFactory’; nested exception is org.springframework.beans.factory. NoSuchBeanDefinitionException: No bean named ‘sqlSessionFactoryBean’ available
Check the code and the introduction of jar packages no problem, the problem is the database data source and sqlSessionFactory is not integrated into a piece
maven configuration
<!--spring boot Integrating mybatis dependencies--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.0.0</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.3.2</version> </dependency> <!-- It is not necessary to refer to the following jar package https://mvnrepository.com/artifact/org.apache.ibatis/ibatis-core --> <!--<dependency> <groupId>org.apache.ibatis</groupId> <artifactId>ibatis-core</artifactId> <version>3.0</version> </dependency>-->
Mybatis configuration class
@Configuration
@MapperScan(basePackages = {
"com.xes.www.core.mapper"
}, sqlSessionFactoryRef = "sqlSessionFactoryBean")
public class MybatisConfiguration {
// Replaces the traditional datasource binding sqlSessionFactoryBean
@Bean
public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
sqlSessionFactoryBean.setDataSource(dataSource);
return sqlSessionFactoryBean;
}
}
So here’s the traditional configuration which is configured through XML
< ! – let Spring manage SQLSessionFactory using MyBatis and Spring integration ->;
< bean id=”sqlSessionFactory” class=”org.mybatis.spring.SqlSessionFactoryBean”>
< ! — database connection pooling –>;
< property name=”dataSource” ref=”dataSource” />
< ! — Loading MyBatis global configuration file –>
< property name=”configLocation” value=”classpath:mybatis/SqlMapConfig.xml” />
< /bean>
Read More:
- Consider defining a bean named ‘entityManagerFactory‘ in your configuration.
- No qualifying bean of type ‘javax.sql.DataSource‘ available: expected at least 1
- shiro Error org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
- Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of ty
- Error creating bean with name ‘sqlsessionfactory’ defined in class path resource
- ModuleNotFoundError: No module named xxx
- [Solved] ModuleNotFoundError: No module named ‘win32api’
- ImportError: No module named indexes.base
- Python:ImportError: No module named indexes.base
- Importerror of Django error: no module named**
- ModuleNotFoundError: No module named ‘tensorflow_core.estimator‘
- Modulenotfounderror: no module named ‘CV2’ – (version problem)
- No module named sklearn.neighbors_ typedefs
- ModuleNotFoundError: No module named ‘ahocorasick‘ [100% Work Method]
- ModuleNotFoundError: No module named ‘notebook‘
- There is no getter for property named ‘id‘ in ‘class java.lang.Integer‘
- matplotlib error – no module named tkinter
- ModuleNotFoundError: No module named ‘MySQLdb‘
- ModuleNotFoundError: No module named ‘tensorboardX‘
- ModuleNotFoundError: No module named ‘mmcv._ext