2015-11-04 128 views
1

我们无法使从部署在Java应用程序DB2数据库连接‘自由Java的’使用JNDI资源在Bluemix问题JNDI资源初始化 - DB连接@“云DB2 - BLUEMIX

它是不能够。初始化资源。

我的server.xml文件是

"<dataSource id="eVotingDataSource" jdbcDriverRef="db2-driver" jndiName="jdbc/DatabaseName" type="javax.sql.DataSource"> 
    <properties.db2.jcc id="eVotingDataSource-props" databaseName="*******" user="db2inst1" password="******" portNumber="50001" serverName="********" sslConnection="true"/> 
</dataSource> 
<jdbcDriver id="db2-driver" libraryRef="db2-library"/> 
<library id="db2-library"> 
    <fileset id="db2-fileset" dir="${server.config.dir}/lib" includes="db2jcc4.jar db2jcc_license_cu.jar"/> 
</library> 

web.xml文件

<resource-ref> 
<description>DB Connection</description> 
<res-ref-name>jdbc/DatabaseName</res-ref-name> 
<res-type>javax.sql.DataSource</res-type> 
<res-auth>Container</res-auth> 

applicationContext.xml文件

<jee:jndi-lookup id="eVotingDataSource" 

JNDI名称= “JDBC /数据库名” 预期型= “javax.sql.DataSource中”/>

下面是消息的输出。登录

org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.nl.abnamro.evoting.dao.IssuerDAOImpl.eVotingSessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eVotingSessionFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'eVotingDataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eVotingDataSource': Invocation of init method failed; nested exception is javax.naming.NamingException: CWWKN0008E: An object could not be obtained for name jdbc/DatabaseName.

Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eVotingDataSource': Invocation of init method failed; nested exception is javax.naming.NamingException: CWWKN0008E: An object could not be obtained for name jdbc/DatabaseName.

Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'eVotingMailSource': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Intermediate context does not exist: mail/Session

当我们加载我们收到以下错误的应用程序:

Error 500: javax.servlet.ServletException: Filter [springSecurityFilterChain]: could not be initialized

您能否协助?

+1

是否为Liberty服务器配置了jndi-1.0功能? – Alasdair

+0

嗨...是的......它被添加到server.xml文件 – Sakthikumar

回答

0

您收到如果您使用的是使用Bluemix结合的DB服务从您的server.xml

jndiName="**jdbc/DatabaseName**" 

CWWKN0008E: An object could not be obtained for name **jdbc/DatabaseName**. 

与此配置相关的错误,当你的应用程序正在上演运行时会自动进行配置,所以你通常不需要在server.xml中提供您自己的配置来覆盖Bluemix配置。 相反,如果你需要覆盖server.xml中为自己的配置,你可以访问你的Bluemix页面上的DB服务引用,在Bluemix控制台下的“环境变量”部分 enter image description here

你可以检索在您的server.xml中使用的DBService名称作为JNDI/[DBNAME]

您还可以检索正确的数据源,以便仅使用在Bluemix上部署应用程序而不覆盖server.xml并检查Bluemix UI(在“文件”部分下)生成的服务器上的数据源的值..xml

只是一点点estion:您能否确认您将自己的应用程序和server.xml一起推送到liberty运行时的打包版本中?

+0

嗨,我在这里使用“云上的DB2”此服务未绑定到Bluemix中的应用程序。所以,我在BLuemix的环境变量部分没有任何东西。另外,我正在推送应用程序以及server.xml文件。如果定义错误 – Sakthikumar

+0

您可以请求帮助您好,要连接到云上的db2,您应该使用如此处所述的jdbc连接字符串https://www.ng.bluemix.net/docs/services/DB2OnCloud/index.html –

+0

否则如果你想使用jndi引用,你必须在你的server.xml中定义一个像这样的数据源< jdbcDriver libraryRef =“DB2JCC4Lib”/>。你可以在这里找到一个例子/answers/questions/164214/how-to-connect-to-a-remote-database-outside-bluemi.html –