[英]How do I set MyBatis configuration properties in an application.properties file in a Spring Boot application?
[英]How do I set a mybatis property in spring boot application.properties file?
我正在開發一個使用 mybatis 的 Spring Boot 應用程序。 我的 mybatis 映射器 xml 有一個 SQL 查詢,其中包含需要從應用程序屬性設置的數據庫模式名稱。 我有一個架構名稱,我想在我的mapper.xml
中將它引用為 ${schema-name}。 我可以在mybatis-config.xml
做到這一點 - 像這樣:
<configuration>
<PropertiesSource url='my properties file"/>
<properties>
<property name='schema-name' value='${database.schema}'/>
</properties>
</configuration>
但我不想使用mybatis-config.xml
。 我想使用spring boot application.properties
進行mybatis配置。
有沒有辦法在spring boot application.properties中設置mybatis的配置屬性? 有人可以幫我弄這個嗎?
如果使用的是mybatis-spring-boot-starter 1.2.0,可以指定如下:
mybatis.configuration-properties.schema-name=abc
或者
mybatis.configuration.variables.schema-name=abc
如果使用mybatis-spring-boot-starter 1.1.1,可以指定如下:
mybatis.configuration.variables.schema-name=abc
如果使用 mybatis-spring-boot-starter 1.0.x,則不能在 application.properties 上指定。 (請更新到 1.1.1+)
請嘗試一下。
謝謝。
在 application.properties 文件中:
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://host/table_name
spring.datasource.username=user
spring.datasource.password=password
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.