JBoss 6 DataSource JNDI Not Found - jboss

I am trying to deploy .war file on JBoss 6 and I have made MySql datasource which I want to access using JNDI.
My Config looks like this :
in myDB-mysql-ds.xml
jndi-name : MyDataSource
in jboss-web.xml
res-ref-name : jdbc/MyDataSource
res-type : javax.sql.DataSource
jndi-name : java:/MyDataSource
in applicationContext.xml
property name="jndiName"
& its value : java:comp/env/jdbc/MyDataSource
When I deploy this war file, It gets bound to MyDatasource like,
INFO [ConnectionFactoryBindingService] Bound ConnectionManager 'jboss.jca:service=DataSourceBinding,name=MyDataSource' to JNDI name 'java:MyDataSource'
but still I get error :
ERROR [[/AppName]] Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: JNDI object with [java:comp/env/jdbc/MyDataSource] not found: JNDI implementation returned null

It is because you are accessing it some wrong way. You should do the following,
<use-java-context>false</use-java-context>
and then access it by its JNDI name.

Related

Unable to access Weblogic datasource through JNDI name using Spring Data JPA

I am using Weblogic 12c and I have configured my datasources like this:
Notice that they are all deployed on target "AdminServer". Also, the "Name" field and "JNDI Name" field are identical. For example, suppose one datasource's name is "MYDS".
Now, when I try to acquire that datasource through Spring Data JPA like this:
#Bean
#Primary
public DataSource businessDataSource() throws IllegalArgumentException, NamingException {
JndiObjectFactoryBean dataSource = new JndiObjectFactoryBean();
dataSource.setResourceRef(true);
dataSource.setJndiName("MYDS");
dataSource.afterPropertiesSet();
return (DataSource) dataSource.getObject();
}
I get the following error when trying to deploy the war file to weblogic:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [javax.sql.DataSource]: Factory method
'businessDataSource' threw exception; nested exception is
javax.naming.NameNotFoundException: Unable to resolve 'MYDS'. Resolved
''; remaining name 'MYDS'
Also I see this error:
DEBUG o.s.jndi.JndiObjectFactoryBean - Converted JNDI name
[java:comp/env/MYDS] not found - trying original name [MYDS].
javax.naming.NameNotFoundException: While trying to look up
comp/env/MYDS in /app/myapp/webclient/404708050.; remaining name
'comp/env/MYDS'
Just looking at the source for setResourceRef and it states :
public void setResourceRef(boolean resourceRef)
Set whether the lookup occurs in a Java EE container,
i.e. if the prefix "java:comp/env/" needs to be added if the JNDI name doesn't already contain it.
Default is "false".
Note: Will only get applied if no other scheme (e.g. "java:") is given.
If you are setting it to true have you tried adding java:comp/env/ to the JNDI name ?

Issue JNDI resource initialization - DB connection #"DB2 on Cloud - BLUEMIX

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

How to change the liferay database to mysql database

I have downloaded the liferay6 bundle with tomcat.I need to change the liferay database to mysql database.I have searched in google and as per information i have created the portal-ext.properties with below lines of code.
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=root123
jdbc.default.jndi.name=jdbc/LiferayPool
schema.run.enabled=true
schema.run.minimal=true
and i modified the ROOT.xml.Now the code in that file is :
<Context path="" crossContext="true">
<Resource
name="jdbc/LiferayPool"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8"
username="root"
password="root123"
maxActive="20"
/>
</Context>
and i have created the lportal database in mysql.Do i need to modify anything more.If i do like this i am not even able to see the default login page of liferay.Can anyone point me where i am doing wrong.Thank You.
I am getting the below Exception if i am doing like this.
java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
at java.net.Socket.connect(Socket.java:579)
at java.net.Socket.connect(Socket.java:528)
at java.net.Socket.<init>(Socket.java:425)
at java.net.Socket.<init>(Socket.java:241)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:271)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2744)
at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:285)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:148)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.liferay.portal.spring.aop.ServiceBeanAutoProxyCreator#0' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'serviceAdvice' while setting bean property 'methodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'asyncAdvice' while setting bean property 'nextMethodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'asyncAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'threadLocalCacheAdvice' while setting bean property 'nextMethodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'threadLocalCacheAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'bufferedIncrementAdvice' while setting bean property 'nextMethodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bufferedIncrementAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'indexableAdvice' while setting bean property 'nextMethodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'indexableAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'transactionAdvice' while setting bean property 'nextMethodInterceptor'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionAdvice' defined in class path resource [META-INF/base-spring.xml]: Cannot resolve reference to bean 'liferayTransactionManager' while setting bean property 'platformTransactionManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liferayTransactionManager' defined in class path resource [META-INF/hibernate-spring.xml]: Cannot resolve reference to bean 'liferayHibernateSessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'liferayHibernateSessionFactory' defined in class path resource [META-INF/hibernate-spring.xml]: Invocation of init method failed; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1327)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1085)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:710)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:410)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at com.liferay.portal.spring.context.PortalContextLoaderListener.contextInitialized(PortalContextLoaderListener.java:172)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:649)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1585)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
1-updating java connector driver
be sure that the liferay portal is not started ! if it does, then shut down.
download and install MySQL and HeidiSQL, you can simply create mysql database via HeidiSql.
download mysql.jar (Connector/J) from dev.mysql.com
you may not login just go below in page and click link: No thanks, just start my download.
delete mysql.jar in liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\lib\ext
copy mysql-connector-java-some version-bin.jar in
\Program Files(x86)\MySQL\Connector J folder and
paste it in liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\lib\ext .(don't forget to rename it to mysql.jar)
2- work with control panel of liferay
now you can start liferay portal
open in browser localhost:8080/
go to -> control panel -> server administration -> Data Migration
JDBC Driver Class Name:
com.mysql.jdbc.Driver
JDBC URL:
jdbc:mysql://localhost:3306/DB-NAME?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
DB-NAME - name of database you've created earlier.
write MySQL username and password then click the button below.
now in the next page you can see some text in the *red border*like : The system is currently undergoing maintenance. Please try again later.
It's allright. just wait for .. may be half an hour or more or less, just wait, and be patient))
while process is going, you can do the next last step:
3- change portal properties
open file portal-ext.properties (create it if doesn't exist) in liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27\webapps\ROOT\WEB-INF\classes and paste to this file following text:
jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost:here must be DB port, by default it's 3306/*DB_NAME*?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=username of MySQL user
jdbc.default.password=password of MySQL user
THAT'S IT
RESTART TOMCAT SERVER
In your portal-ext.properties file, it should be enough if you specif JNDI name to lookup.
jdbc.default.jndi.name=MyDataSource
In your Tomcat's xml file,
<Resource
name="MyDataSource"
auth="Container"
type="javax.sql.DataSource"
driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8"
username="root"
password="root123"
maxActive="20"
/>
Make sure that the user you are using above (root) has privilege to create the tables.
Also, don't forget to restart your Tomcat container.
Even on top of this if it doesn't work, share the exceptions in your (bin) logs.

error on integrating spring data jpa with spring batch admin

o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productfeedSvc':
Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field:
private com.dealwallet.productFeed.repository.ProductFeedRepository
com.dealwallet.productFeed.svc.impl.ProductSvcImpl.productFeedRepository;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productFeedRepository': Initialization of bean failed; nested exception is java.lang.NoSuchMethodError: **org.springframework.transaction.interceptor.TransactionInterceptor.setTransactionManagerBeanName(Ljava/lang/String;)**V
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:287) ~[spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]
I am using spring data jpa with spring batch admin,
i configured application-context.xml and persistance.xml,
when am running this in tomcat i got this error.
It says there is problem in auto-wiring.
So check these items:
- Make sure your class (the one which is using the other) has setter for that property.
- Make sure your class's property (the one which is using the other) has the exact name of the other class bean id.
- Make sure you have enabled annotations.

Deployment issues on Tomcat

I am unable to deploy grails war in tomcat .
Copied all 55 jars to $CATALINA_HOME/shared/lib/grails-jars/
Added shared.loader= ${catalina.home}/shared/lib/grails-jars/*.jar
And started tomcat successfully. Now deployed grails war in deploy folder (war is ~572.4KB).
The console shows these errors :
log4j:ERROR Could not instantiate appender named "CONSOLE".
28 Jan, 2010 11:35:57 AM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring root WebApplicationContext
2010-01-28 11:36:06,294 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] ERROR context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory';
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed;
nested exception is org.hibernate.MappingException: Could not get constructor for org.codehaus.groovy.grails.orm.hibernate.persister.entity.GroovyAwareSingleTableEntityPersister
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
My application contains 4 plugins :
hibernate-1.1.2
liferay-exploded-0.8
portlets-0.7
portlets-liferay-0.1
Could any one please help me .
thanks in advance .
Sounds like this might be a Hibernate version problem, as described here.