I have a Spring-Boot-Aplication with the following dependencyManagement
:
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.1.5.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
and the following dependencies
:
spring-boot-starter-jersey
spring-boot-starter-jdbc(exclusion:tomcat-jdbc)
HikariCP(version:3.3.1)
ojdbc7
On Tomcat I configured a JNDI-Datasource as:
<Resource name="jdbc/myDS"
type="javax.sql.DataSource"
driverClassName="oracle.jdbc.driver.OracleDriver"
username="Superuser"
password="secret"
url="jdbc:oracle:thin:@xxxDbX"
../>
In the .properties
-file I added the following properties:
spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource
spring.datasource.jndi-name=jdbc/myDS
As Spring-Boot
is able to configure a DataSource from the properties, I let it do so and I do write no extra code for a DataSource.
Deployed in a Standalone Tomcat it works perfectly.
Logically Spring Boot can not find the JNDI-Resource in an embedded Tomcat and starting the application as a Spring-Boot-Application I got:
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.datasource.type' to java.lang.Class<javax.sql.DataSource>:
Property: spring.datasource.type
Value: org.apache.tomcat.jdbc.pool.DataSource
Origin: class path resource [application.properties]:12:24
Reason: No converter found capable of converting from type [java.lang.String] to type [java.lang.Class<javax.sql.DataSource>]
Action:
Update your application's configuration
I would like to be able to start the application as a Spring-Boot-Application and also build a war-file which can be deployed in any Standalone Tomcat.
Is this possible by adding properties
for a second DataSource in case the application is started as a Spring-Boot-Application or I am obliged to have a second .properties
file?