J'utilise Spring Boot 1.4.2.RELEASE
. J'utilise également Tomcat 8.5.9
(NON intégré) et Java 8
.Spring Boot et Tomcat ne trouvent pas de ressources JNDI
Dans mon fichier application.properties
, je peux configurer manuellement mon datasource en utilisant:
spring.datasource.url = jdbc:as400://blahblah....
spring.datasource.username = myuser
spring.datasource.password = password
spring.datasource.driver-class-name=com.ibm.as400.access.AS400JDBCDriver
Cela fonctionne très bien. Mais, nous utilisons Tomcat pour héberger nos connexions. Dans Tomcat, nous avons:
<GlobalNamingResources>
<Resource name="jdbc/BLAH" ..... />
</GlobalNamingResources>
Je puis changé application.properties à:
spring.datasource.jndi-name=java:comp/env/jdbc/BLAH
spring.jpa.database-platform=org.hibernate.dialect.DB2400Dialect
spring.jpa.show-sql=true
Maintenant, je ne peux même pas construire l'application. Je reçois l'exception suivante:
o.s.w.c.s.GenericWebApplicationContext :
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration':
Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'dataSource' defined in class path resource
[org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.class]:
Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [javax.sql.DataSource]:
Factory method 'dataSource' threw exception; nested exception is
org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException:
Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/BLAH';
nested exception is javax.naming.NoInitialContextException:
Need to specify class name in environment or system property, or as an applet parameter,
or in an application resource file: java.naming.factory.initial
Le NoInitialContextException
me porte à croire que le printemps Boot ne peut pas trouver Tomcat en cours d'exécution, il ne peut donc pas effectuer une recherche JNDI.
Gardez à l'esprit, le exact même configuration a travaillé pour nous en utilisant Spring Boot 1.2.5.RELEASE. Nous avons une autre application qui utilise 1.2.5.RELEASE, Java 7 et Tomcat 7 et fonctionne avec les ressources JNDI. Mais en utilisant le nouveau Spring Boot, Java 8 et Tomcat 8 ne le fait pas.
Toute aide est appréciée.
Quelques extraits de mon pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/>
</parent>
...
<dependencies>
<dependency>
<groupId>net.sf.jt400</groupId>
<artifactId>jt400</artifactId>
<version>6.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
....
</dependencies>
Autres extraits de code:
@SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(basePackages = "com.company.myapp")
@EnableJpaRepositories(basePackages = "com.company.myapp.repository")
@EnableTransactionManagement
@EnableVaadin
@EnableVaadinServlet
public class AppConfiguration {
}
MISE À JOUR
J'ai créé les ressources dans Tomcat (externe) en utilisant la GlobalNamingResources
dans notre server.xml
. Cela fonctionne pour d'autres applications.
MISE À JOUR 2
oublié de mentionner que je suit dans un fichier src/main/webapp/META-INF/context.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<ResourceLink global="jdbc/BLAH"
name="jdbc/BLAH"
type="com.mchange.v2.c3p0.ComboPooledDataSource"/>
</Context>
MISE À JOUR 3
, je veux aussi préciser le problème se passe pendant l'étape maven package
.
Avez-vous essayé de référencer la ressource avec une barre oblique précédente? (c'est-à-dire java:/...) spring.datasource.jndi-name = java:/comp/env/jdbc/BLAH –
Désolé, je ne suis pas ce que vous dites. – cbmeeks
Non. Toujours le même. J'ai aussi essayé '/ jdbc/BLAH' et' jdbc/BLAH'. – cbmeeks