2015-11-04 134 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 –