springboot read tomcat-context.xml

后端 未结 1 421
日久生厌
日久生厌 2021-01-18 17:47

Hi we got a spring application running on tomcat application-server. I want to add integration tests with Springboot in JUnit. I now got the problem that the embedded tomcat

相关标签:
1条回答
  • 2021-01-18 18:41

    Spring Boot offer many ways to externalize your configuration...

    You can define your datasource properties in your tomcat/conf/Catalina/<host> context descriptors.

    You could define your jndi name:

    <Context>
        <Parameter name="spring.datasource.jndi-name" value="/pathToYourDatasource" />
    </Context>
    

    Or define the datasource:

    <Context>
        <Parameter name="spring.datasource.url" value="your url" />
        <Parameter name="spring.datasource.username" value="your username" />
        <Parameter name="spring.datasource.password" value="your password" />
    </Context>
    

    Even define the path to an application.properties and set here your configuration:

    <Context>
        <Parameter name="spring.config.location" value="/path/to/application.properties" />
    </Context>
    

    This way is not necessary set programmatically your hardcoded datasource and you can put another database configuration for testing in src/test/resources/application.properties:

    spring.datasource.url=
    spring.datasource.username=
    spring.datasource.password=
    
    0 讨论(0)
提交回复
热议问题