我有myBatis xml配置SqlMapConfig.xml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE configuration
PUBLIC '-//mybatis.org//DTD Config 3.0//EN'
'http://mybatis.org/dtd/mybatis-3-config.dtd'>
<configuration>
<!--<typeAliases>-->
<!--<typeAlias alias = "class_alias_Name" type = "absolute_clas_Name"/>-->
<!--</typeAliases>-->
<environments default = "development">
<environment id = "development">
<transactionManager type = "JDBC"/>
<dataSource type = "POOLED">
<property name = "driver" value = "oracle.jdbc.driver.OracleDriver"/>
<property name = "url" value = "jdbc:oracle:thin:@my_ip:port/dbname"/>
<property name = "username" value = "username"/>
<property name = "password" value = "password"/>
</dataSource>
</environment>
</environments>
<!--<mappers>-->
<!--<mapper resource = "path of the configuration XML file"/>-->
<!--</mappers>-->
</configuration>
我有依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
我有仓库
@Mapper
public interface ImsiByMsisdnModelRepository {
final String query = "....";
@Select(query )
@Results(value = {
@Result(property = "msisdn", column = "MSISDN"),
@Result(property = "terminalid", column = "TERMINALID"),
@Result(property = "startDate", column = "START_DATE"),
@Result(property = "endDate", column = "END_DATE"),
})
List<ImsiByMsisdnModel> getAll(@Param("msisdn") String msisdn);
}
但当我尝试构建priject时,我得到了错误
描述:
无法确定数据库类型NONE 的嵌入式数据库驱动程序类
行动:
如果您想要嵌入式数据库,请在类路径。如果要从您可能需要激活特定配置文件(没有配置文件当前活动(。
如何设置SqlMapConfig.xml
?
我尝试在application.properties
行中写入
mybatis.config-location=
但我不知道写哪条路。SqlMapConfig.xml
放置在资源中
当您有依赖时
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
spring-boot将自动配置spring-jdbc和mybatis这两个。它在spring-jdbc中使用的唯一配置是spring.datasource.*
,如果您错过了它们,则会出现错误(出现此错误是因为自动配置springjdbc失败(。
那么你该怎么办呢?添加spring.datasource.*
,可以成功地自动配置spring-jdbc。
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://host/table_name
spring.datasource.username=user
spring.datasource.password=password
那么你的mybatis将自动配置成功。
我发现您所要做的就是将以下内容添加到application.properties文件中:
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://host/table_name
spring.datasource.username=user
spring.datasource.password=password