Spring to Wildfly Deploy - javax.naming.NameNotFoundException(JNDI)

时间:2015-03-31 08:12:47

标签: java spring postgresql spring-boot wildfly-8

我正在尝试将我的spring-boot应用程序部署到WildFly版本8.1, 但每次应用尝试启动时,我都会收到javax.naming.NameNotFoundException。

我的配置:
我将JDBC作为模块添加到WildFly-Standalone实例中。
    module.xml:     

<module xmlns="urn:jboss:module:1.1" name="org.postgresql">

    <resources>
       <resource-root path="postgresql-9.4-1201.jdbc41.jar"/>
    </resources>

    <dependencies>
       <module name="javax.api"/>
       <module name="javax.transaction.api"/>
    </dependencies>
</module>

之后我定义了驱动程序:

<driver name="postgresql" module="org.postgresql">
  <driver-class>org.postgresql.Driver</driver-class>
  <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
  <datasource-class>org.postgresql.ds.PGSimpleDataSource</datasource-class>
</driver>

然后将数据源添加到standalone.xml

<datasource jndi-name="java:jboss/jdbc/MyDS" pool-name="MyDS" enabled="true">
  <connection-url>jdbc:postgresql://localhost:5432/databasename</connection-url>
  <driver>postgresql</driver>
  <security>
    <user-name>username</user-name>
  </security>
</datasource>

通过JBoss-CLI测试连接会取得成功。

所以现在我尝试通过以下方式加载DataSource:

@Bean
public DataSource getDataSource() {
   JndiDataSourceLookup dataSourceLookup = new JndiDataSourceLookup();
   DataSource dataSource = dataSourceLookup.getDataSource(this.jndiName);
   return dataSource;
}

当我通过jboss-cli部署时:

 deploy /path/to/myapplication.war

我明白了:

Caused by: org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:jboss/jdbc/MyDS'; nested exception is javax.naming.NameNotFoundException; remaining name 'java:jboss/jdbc/MyDS'
Caused by: javax.naming.NameNotFoundException; remaining name 'java:jboss/jdbc/MyDS'"}}}}

版本:

  • spring-boot 1.2.2.RELEASE
  • wildfly-8.2.0Final

感谢您的帮助:)

0 个答案:

没有答案