Springboot read tomcat-context.xml

Hi we got spring application running on tomcat app server. I want to add integration tests using Springboot to JUnit. I am now having the problem that the embedded tomcat server does not store our datasource and therefore cannot be found ... If there is no specific datasource in the server configuration, we got a fallback "context.xml" in our resources that should be used. But the built-in tomcat doesn't read this config and I just can't figure out how to do it. Below is the point of failure in my JUnit test as it cannot find this JNDI name in the embedded tomcat:

@Bean
public DataSource dataSource()
{
  return new JndiDataSourceLookup().getDataSource("jdbc/myDB");
}

      

fallback context.xml looks like this:

<Context>
<!-- HSQL -->
   <Resource name="jdbc/myDB" auth="Container"
             type="javax.sql.DataSource" driverClassName="org.hsqldb.jdbcDriver"
             url="jdbc:hsqldb:mem:mymemdb;shutdown=true" username="SA" password=""
             maxTotal="100" maxIdle="5" maxWaitMillis="10000"/>

   <Manager pathname=""/>
</Context>

      

how can i push this file to embedded tomcat on startup?

+3


source to share


1 answer


Spring Boot many ways to do emergency setup ...

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

.

You can define your jndi name:

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

      

Or define the data source:



<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>

      

Define the path to application.properties

and specify your config here:

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

      

This method does not require you to programmatically program your data source hard drive, and you can put a different database configuration for testing in src/test/resources/application.properties

:

spring.datasource.url=
spring.datasource.username=
spring.datasource.password=

      

0


source







All Articles