带有 tomcat 数据源的 spring boot

springboot with tomcat datasource

在开发模式下 springboot 可以使用 tomcat 数据源吗?

我想将我的项目配置为使用 tomcat 数据源,因此,当我创建一个 .war 并在我的 tomcat 客户端部署时,配置了数据源的工作正常

但是我如何将其与 mvn spring-boot:运行 一起使用?

看来你想要的是针对不同的环境使用不同的配置。

您需要的是利用 Spring Profiles。通过设置变量 spring.profiles.active,您可以定义当前的环境设置。

例如,在生产中,当您 运行 您的应用程序时,您在 JVM 设置中设置了:

java -Dspring.profiles.active=production ...

但是当您开发应用程序时,在您的 IDE 中将设置设置为

spring.profiles.active=development

我通常使用 Spring 启动配置 using YAML, and then I define environment specific settings by defining a multi-profile document:

spring:
  profiles: development,default
  datasource:
    url: "jdbc:postgresql://localhost:1543/jedis"
    username: "luke"
    password: "sk1walk3r!"
    driver-class-name: "org.postgresql.Driver"
spring:
  profiles: production
  datasource:
    jndi-name=java:jboss/datasources/jedis

通过这种方式,您可以轻松更改在 IDE 中进行开发或调试时使用的设置等

可能还有一种方法可以使用属性文件来实现,但我不知道,因为我一直使用 YAML。