如何用spring boot 内嵌tomcat,用jndi方式配置多个数据源?
不知道你这个问题是否已经解决, 如果还没有解决的话: <profile>
<id>product</id>
<properties>
<logback.loglevel>INFO</logback.loglevel>
<spring.profiles.active>product</spring.profiles.active>
<profile.product>true</profile.product>
<profile.properties>file:/tomcat/profiles/${project.artifactId}/properties</profile.properties>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<configuration>
<argLine>-Xms512m -Xmx1024m</argLine>
<forkMode>once</forkMode>
<skip>true</skip>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
</profile>
根据引入的pom可知 外部配置文件路径为 /tomcat/profiles/${project.artifactId}/properties
spring:
datasource:
jndi-name: jdbc/lcs_ds
修改server.xml加入数据源配置
<Resource name="jdbc/lcs_ds"
auth="Container"
type="javax.sql.DataSource"
username="xxxx"
password="xxxx"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://xxxx:3306/lcs?useUnicode=true&characterEncoding=utf8&useSSL=false&rewriteBatchedStatements=true"
maxActive="100"
maxIdle="10"
maxWait="2000"
removeAbandoned="true"
logAbandoned="true"
logExpiredConnections="true"
maxConnLifetimeMillis="60000"
initialSize="1"
removeAbandonedTimeout="180"
validationQuery="select 1"
testOnBorrow="true"
testWhileIdle="true"
timeBetweenEvictionRunsMillis="3600000"
minEvictableIdleTimeMillis="18000000" />
修改context.xml引入数据源配置
<ResourceLink global="jdbc/lcs_ds" name="jdbc/lcs_ds" type="javax.sql.DataSource"/>
也可直接将数据源信息配置到context.xml中
项目打指定profile war包,修改数据源信息可直接在外部配置文件中修改 不用重新打包