1
votes

We are unable to make DB2 database connection from Java application deployed on "Liberty on Java" using JNDI resource at Bluemix.

It is not able to initialize the resource.

My server.xml file is

 "<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 file

<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 file

<jee:jndi-lookup id="eVotingDataSource"

jndi-name="jdbc/DatabaseName" expected-type="javax.sql.DataSource" />

Below is output of messages.log

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

When we load the application we receive the following error:

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

Could you please assist?

1
Is the feature jndi-1.0 configured for the Liberty server?Alasdair
Hi...Yes...it is added in server.xml fileSakthikumar

1 Answers

0
votes

The error you are receiving is related with this configuration from your server.xml

jndiName="**jdbc/DatabaseName**"

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

If you are using a DB service bound using Bluemix, the runtime is automatically configured when your application is staging, so you usually don't need to provide your own configuration in your server.xml overwriting the Bluemix configuration. Instead, if you need to overwrite the server.xml for your own configurations, you could access the DB service references on your Bluemix page, on the Bluemix console under the 'Environment Variables' section enter image description here

You could retrieve the DBService name to use inside your server.xml as JNDI/[DBNAME]

You could also retrieve the right Datasource to use simply deploying your app on Bluemix without overwriting the server.xml and check on the Bluemix UI (under Files section) the value of the Datasource on the produced server.xml

Just a little question: Could you confirm that you are pushing your application along with your server.xml, within a packaged version of your liberty run-time ?