Spring boot-JNDI-datasource-lookup - Name comp/env/jdbc nicht im Kontext "java:"

Ich habe setup eine spring-boot - (v 1.1.9) - Anwendung bereitstellen, wie eine war-Datei. Und ich bin versucht zu integrieren, diese web-Anwendung mit einem bestehenden Daten-service-Modul (Hinzugefügt als maven-dependency).

Umgebung, die versucht zu implementieren: WebSphere Application Server 8.5.5.4

Das Problem, das ich bin vor ist eine Anwendung, die start-up-Fehler, wenn Sie versuchen zu schauen-eine JNDI-Datenquelle (jdbc/fileUploadDS), wie unten in der abhängigen Daten-service-Modul.

@Configuration
@Profile("prod")
public class JndiDataConfig implements DataConfig {

    @Bean
    public DataSource dataSource() throws NamingException {
          Context ctx = new InitialContext();
          return (DataSource) ctx.lookup("java:comp/env/jdbc/fileUploadDS");
    }

}

Mein Spring-Boot-Konfiguration:

@Configuration
@ComponentScan(basePackages = { "au.com.aiaa.fileupload.data.*", "demo" })
@EnableAutoConfiguration(exclude = { HibernateJpaAutoConfiguration.class, DataSourceAutoConfiguration.class })
public class SampleApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(applicationClass, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }

    private static Class<SampleApplication> applicationClass = SampleApplication.class;

    @Bean
    public static Properties fileUploadJndiProperties() throws NamingException {
        JndiObjectFactoryBean jndiFactoryBean = new JndiObjectFactoryBean();
        jndiFactoryBean.setJndiName("props/FileUploadProperties");
        jndiFactoryBean.setExpectedType(Properties.class);
        jndiFactoryBean.setLookupOnStartup(true);
        jndiFactoryBean.afterPropertiesSet();
        return (Properties) jndiFactoryBean.getObject();
    }

}

Beachten Sie, dass ich in der Lage bin, zu lookup Requisiten/FileUploadProperties erfolgreich. Aber nicht, das gleiche zu tun für eine datasource.

Meine Frage ist, es versucht zu laden EmbeddedWebApplicationContext das ist nicht das, was ich will.

Der stack trace:

Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource au.com.aiaa.fileupload.data.dao.configuration.JndiDataConfig.dataSource() throws javax.naming.NamingException] threw exception; nested exception is **javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".**
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:301)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1186)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:706)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
        at **org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)**
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
        at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142)
        at org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:89)
        at org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:51)
        at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)


..................

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.sql.DataSource au.com.aiaa.fileupload.data.dao.configuration.JndiDataConfig.dataSource() throws javax.naming.NamingException] threw exception; nested exception is **javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".**
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:586)
        ... 132 common frames omitted
Caused by: javax.naming.NameNotFoundException: Name comp/env/jdbc not found in context "java:".
        at com.ibm.ws.naming.ipbase.NameSpace.getParentCtxInternal(NameSpace.java:1970)
        at com.ibm.ws.naming.ipbase.NameSpace.retrieveBinding(NameSpace.java:1377)
        at com.ibm.ws.naming.ipbase.NameSpace.lookupInternal(NameSpace.java:1220)
        at com.ibm.ws.naming.ipbase.NameSpace.lookup(NameSpace.java:1142)
        at com.ibm.ws.naming.urlbase.UrlContextImpl.lookupExt(UrlContextImpl.java:1436)
        at com.ibm.ws.naming.java.javaURLContextImpl.lookupExt(javaURLContextImpl.java:477)
        at com.ibm.ws.naming.java.javaURLContextRoot.lookupExt(javaURLContextRoot.java:485)
        at com.ibm.ws.naming.java.javaURLContextRoot.lookup(javaURLContextRoot.java:370)
        at org.apache.aries.jndi.DelegateContext.lookup(DelegateContext.java:161)
        at javax.naming.InitialContext.lookup(InitialContext.java:436)
        at au.com.aiaa.fileupload.data.dao.configuration.JndiDataConfig.dataSource(JndiDataConfig.java:41)
        at au.com.aiaa.fileupload.data.dao.configuration.JndiDataConfig$$EnhancerBySpringCGLIB$$8001dbbe.CGLIB$dataSource$0(<generated>)
        at au.com.aiaa.fileupload.data.dao.configuration.JndiDataConfig$$EnhancerBySpringCGLIB$$8001dbbe$$FastClassBySpringCGLIB$$3c9e0518.invoke(<generated>)
        at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
        at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
        at au.com.aiaa.fileupload.data.dao.configuration.JndiDataConfig$$EnhancerBySpringCGLIB$$8001dbbe.dataSource(<generated>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
        at java.lang.reflect.Method.invoke(Method.java:611)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)

Was vermisse ich hier? Selbst wenn ich versuche, explizit definieren Sie die dataSource-bean-Methode in SampleApplication.java wie unten schlägt er mit dem gleichen Fehler.

@Bean
    public static DataSource dataSource() throws NamingException {
        JndiObjectFactoryBean jndiFactoryBean = new JndiObjectFactoryBean();
        jndiFactoryBean.setJndiName("java:comp/env/jdbc/fileUploadDS");
        jndiFactoryBean.setExpectedType(DataSource.class);
        jndiFactoryBean.setLookupOnStartup(true);
        jndiFactoryBean.setResourceRef(true);
        jndiFactoryBean.afterPropertiesSet();
        return (DataSource) jndiFactoryBean.getObject();
    }

Bezog ich mich diese und es sagt, wir müssen enableNaming() auf der servlet-container? Kann ich etwas tun, ähnlich wie bei nicht eingebetteten web-Anwendung Kontext? Oder ist es rein eine 8,5 Problem??

Haben Sie versucht, die JndiObjectFactoryBean OHNE die java:comp/env/ Teil?
Sie müssen auf den Ressource-Referenz mit jdbc/fileUploadDS Namen in Ihrem web.xml. Und stellen Sie sicher, es ist gebunden an die tatsächliche datasource-name während der installation oder über ibm-web-bnd.xml - Datei.
Danke @Gas-es funktioniert. Ich fügte hinzu, die resource-ref in web.xml gebunden und die Ressource-Referenz, um die tatsächliche Datenquelle während der installation in der Administrationskonsole. Aber wie kann ich erreichen, das gleiche, ohne eine web.xml in meinem spring-boot-Anwendung? Ich lese hier wie ersetzen <servlet>, <servlet-mapping> oder <filter - >, <filter-mapping> innerhalb von spring-boot-configuration-Klasse, die sich SpringBootServletInitializer. Gibt es eine Entsprechung für <resource-ref> wie auch?

InformationsquelleAutor Dinusha Kariyawasam | 2014-12-15

Schreibe einen Kommentar