如何用spring boot 内嵌tomcat,用jndi方式配置多个数据源?
1条回答 默认 最新
关注 不知道你这个问题是否已经解决, 如果还没有解决的话:- 文章:SpringBoot内嵌Tomcat JNDI配置 中也许有你想要的答案,请看下吧
- 除此之外, 这篇博客: springboot+tomcat+jndi实现外置配置文件配置多数据源中的 使用JNDI 部分也许能够解决你的问题, 你可以仔细阅读以下内容或者直接跳转源博客中阅读:
- 引入pom指定外部配置文件路径:
<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
- 修改tomcat配置文件
修改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包,修改数据源信息可直接在外部配置文件中修改 不用重新打包
如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^解决 无用评论 打赏 举报
悬赏问题
- ¥15 求差集那个函数有问题,有无佬可以解决
- ¥15 【提问】基于Invest的水源涵养
- ¥20 微信网友居然可以通过vx号找到我绑的手机号
- ¥15 寻一个支付宝扫码远程授权登录的软件助手app
- ¥15 解riccati方程组
- ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
- ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
- ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
- ¥50 树莓派安卓APK系统签名
- ¥65 汇编语言除法溢出问题