I am trying to create a datasource bean for MySQL from within my Spring project (in springtoolsuite), and I want to
access the MySQL JNDI (run by JBoss application server).
My Bean declaration
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean" scope="singleton" >
<property name="jndiName" value="java:/MySqlDS" />
<property name="resourceRef" value="true" />
And from JBoss console:
java: Namespace
+- MySqlDS (class: org.jboss.resource.adapter.jdbc.WrapperDataSource)
However when I ran my test application, I got the following. What have I done wrong?
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in file [/workspace-sts/test1/cspringbean.xml]: Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1401)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:540)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
at com.don22.EscortIdol.main(EscortIdol.java:13)
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:325)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
... 12 more
I would also suggest taking a look at the JEE namespace rather than defining the factory bean
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/MyDataSource"/>
See http://static.springsource.org/spring/docs/2.5.6/reference/xsd-config.html
javax.naming.NoInitialContextException:
Need to specify class name in
environment or system property, or as
an applet parameter, or in an
application resource file:
java.naming.factory.initial
This message in the stack trace leads me to believe that either you didn't set up a JNDI data source pool in JBoss or your JNDI name is incorrect. Check both.
UPDATE: How is your app doing the JNDI lookup with JBOSS? If you aren't deployed in an app server, then you should be using the DriverManagerDataSource, not the JNDI data source.
Related
I am currently using Spring Boot and I'm trying to include a library class which is currently used in a Java EE context. In this filename.jar there is an implementation of EJB file which has a #Resource(mappedName="java:/TDS" injection as dataSource.
This dataSource has been configured in a persistence.xml as below:
persistenc.xml
<persistence-unit name="defaultTDSoft">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:/TDS</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.InformixDialect"/>
</properties>
</persistence-unit>
EJB file
#Stateless
#Remote({ContactenManagerRemote.class})
public class ContactenManager implements ContactenManagerRemote {
private transient Logger logger = Logger.getLogger(this.getClass().getName());
#PersistenceContext
private EntityManager manager;
#Resource( mappedName = "java:/TDS" )
private DataSource mydb;
public ContactenManager() {
}
}
I am trying to inject this EJB in a spring boot via BeanConfiguration.java as below:
#Configuration
#EntityScan(basePackageClasses = {de.mavin.model.entities.AfingEntity.class, de.mavin.model.session.impl.contactenManage.class, OntEntityIntern.class})
public class TDSoftBeanConfiguration {
#Bean
public ContactenManager contactenManager(){
return new ContactenManager();
}
}
Error:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'java:/TDS' defined in JNDI environment: JNDI lookup failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.jndi.support.SimpleJndiBeanFactory.getBean(SimpleJndiBeanFactory.java:129) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:504) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:653) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:224) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:116) ~[spring-beans-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessProperties(CommonAnnotationBeanPostProcessor.java:334) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
... 22 common frames omitted
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) ~[na:1.8.0_252]
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313) ~[na:1.8.0_252]
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350) ~[na:1.8.0_252]
at javax.naming.InitialContext.lookup(InitialContext.java:417) ~[na:1.8.0_252]
at org.springframework.jndi.JndiTemplate.lambda$lookup$0(JndiTemplate.java:157) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:92) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:157) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179) ~[spring-context-5.2.0.RELEASE.jar:5.2.0.RELEASE]
I use the latest version of spring-boot with java 8, JEE 8.
Any solution to this problem is very welcome?
I was trying to migrate a war deployed in jboss to tomcat 8. I am facing the below exception while loading my application context xml. This was working in jboss. (Had Same issue with dataSource, but it got fixed when I configured <GlobalNamingResources/> settings in context.xml.)
Application context has
..
<jee:jndi-lookup id="txnService" jndi-name="services/TxnService"
lazy-init="true" />
<jee:jndi-lookup id="mailService" jndi-name="services/MailService"
lazy-init="true" expected-type="com.tone.mailservice.MailService" />
..
And error:
Caused by: javax.naming.NameNotFoundException: Name [services/MailService] is not bound in this Context. Unable to find [services].
and
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txnService': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [services/TxnService] is not bound in this Context. Unable to find [services].
I can see the TxnService class has the following code.
public abstract interface TxnService
{
public static final String JNDI_NAME = "services/TxnService";
..
}
This class is inside a jar and i have that jar inside the lib folder.
I have tried giving java:/comp/env/services/TxnService and java:/comp/env/services/MailService instead. But still same issue.
Full trace:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailService': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [services/MailService] is not bound in this Context. Unable to find [services].
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:1146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1096)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 45 more
Caused by: javax.naming.NameNotFoundException: Name [services/MailService] is not bound in this Context. Unable to find [services].
at org.apache.naming.NamingContext.lookup(NamingContext.java:816)
at org.apache.naming.NamingContext.lookup(NamingContext.java:173)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 54 more
Related cause:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txnService': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [services/TxnService] is not bound in this Context. Unable to find [services].
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1482)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getTypeForFactoryBean(AbstractBeanFactory.java:1368)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:720)
at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:523)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:356)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:334)
at org.springframework.beans.factory.BeanFactoryUtils.beanNamesForTypeIncludingAncestors(BeanFactoryUtils.java:187)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:897)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:855)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:795)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:723)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:196)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1045)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:949)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:599)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:518)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:459)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4940)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5250)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.NameNotFoundException: Name [services/TxnService] is not bound in this Context. Unable to find [services].
at org.apache.naming.NamingContext.lookup(NamingContext.java:816)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.apache.naming.NamingContext.lookup(NamingContext.java:827)
at org.apache.naming.NamingContext.lookup(NamingContext.java:159)
at org.apache.naming.NamingContext.lookup(NamingContext.java:827)
at org.apache.naming.NamingContext.lookup(NamingContext.java:173)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:163)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1541)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1479)
... 51 more
Your problem seems to be a JNDI lookup related issue.
Actually, I am trying to provide a fulfill procedure for JBoss to Tomcat migration. Here I have not given the specific answer. Please follow the procedure. After that, if any issue arise, we would start further discussion.
There are mainly 3 areas need to be considered for migration between jboss and tomcat8.
Common libraries,
Data source configutation,
JNDI bindings and basic server configuration
Common libraries:
For Tomcat:
Apache Tomcat stores the common libraries into the CATALINE_HOME/lib folder.
For JBoss:
JBoss AS release ==== Path for common libs
4.x ================= JBOSS_HOME/server/[server-name]/lib
5.x - 6.x============ JBOSS_HOME/common/lib
7.x ================= JBOSS_HOME/modules
Resource Link:
http://www.mastertheboss.com/jboss-as-7/how-to-install-a-module-on-jboss-as-7
Data Source Configuration
If you use Oracle as database then
For Tomcat
A Datasource is configured in the context.xml file of Tomcat:
<Resource name="jdbc/oracledb"
auth="Container"
type="javax.sql.DataSource"
username="scott"
password="tiger"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:#localhost:1521:XE"
maxActive="10"
maxIdle="2"
removeAbandoned="true"
removeAbandonedTimeout="30"
maxWait="5000"
logAbandoned="true"
accessToUnderlyingConnectionAllowed="true"/>
then, you should add your JDBC driver into CATALINA_HOME/lib folder
For JBoss:
JBoss AS release ======== Path for data source
4.x - 5.x - 6.x ======== datasource-ds.xml file into JBOSS_HOME/server/[server-name]/deploy
7.x ===================== datasource-ds.xml file into JBOSS_HOME/standalone/deployments or as a module into JBOSS_HOME/modules
JNDI bindings and basic server configuration
In JNDI binding, code related changing should be required in tomcat. JNDI binding can be done in 2 ways.
Using lookup code
Using the #Resource annotation (javax.annotation.Resource) instead of the lookup code
Using lookup code
We can look up the configured JNDI DataSource using Java code as follows:
Context initContext = new InitialContext();
Context envContext = (Context) initContext.lookup("java:comp/env");
DataSource ds = (DataSource) envContext.lookup("jdbc/UsersDB");
Connection conn = ds.getConnection();
After obtaining the connection, we can use it as trivial JDBC code:
And then
Statement statement = conn.createStatement();
String sql = "select username, email from users";
ResultSet rs = statement.executeQuery(sql);
// iterates over the result set...
Using the #Resource annotation (javax.annotation.Resource) instead of the lookup code
It needs to declare a field called dataSource in the servlet like this:
#Resource(name = "jdbc/UsersDB")
private DataSource dataSource;
Tomcat will look up the specified resource name and inject an actual implementation when it discovers this annotation.
For full source code with example, you can go through this tutorial: Configuring JNDI DataSource for Database Connection Pooling in Tomcat
For JBoss:
when using JBoss AS 7 you have to choose a JNDI location like java:/ or java:/jboss for your datasources in order to be accepted. The portable approach for defining data sources is to use a resource reference.
In our example, we need to define into your web.xml for your connection pool:
DB Connection
jdbc/oracledb
javax.sql.DataSource
Container
Alternatively, starting in Java EE 5 (Servlet 2.5), this can be done even easier within your code using the #Resource annotation.
public class MyServlet extends HttpServlet {
#Resource(name = "jdbc/oracledb")
private DataSource dataSource;
Then on the JBoss side define in your jboss-web.xml
<jboss-web>
<resource-ref>
<res-ref-name>jdbc/oracledb</res-ref-name>
<jndi-name>java:jboss/datasources/jdbc/oracledb</jndi-name>
</resource-ref>
</jboss-web>
Fine, now your JNDI lookup will work in either environment, without changing one line of code!
Server Configuration
by default both Tomcat and JBoss are delivering http applications on port 8080, chances are that you might need configuring the http port. Here's tomcat's server.xml
<Connector port="32080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Resource Link:
Tomcat DataSource JNDI Example in Java
Tomcat to JBoss migration
After of implement the persistence with "MySQL" (http://activemq.apache.org/jdbc-support.html)
I'm find the next problem:
File config: --> activemq.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
<!-- Allows us to use system properties as variables in this configuration file -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:${activemq.conf}/credentials.properties</value>
</property>
</bean>
<!-- Allows accessing the server log -->
<bean id="logQuery" class="io.fabric8.insight.log.log4j.Log4jLogQuery"
lazy-init="false" scope="singleton"
init-method="start" destroy-method="stop">
</bean>
<!--
The <broker> element is used to configure the ActiveMQ broker.
-->
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" >
<!-- The constantPendingMessageLimitStrategy is used to prevent
slow topic consumers to block producers and affect other consumers
by limiting the number of messages that are retained
For more information, see:
http://activemq.apache.org/slow-consumer-handling.html
-->
<pendingMessageLimitStrategy>
<constantPendingMessageLimitStrategy limit="1000"/>
</pendingMessageLimitStrategy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<!--
The managementContext is used to configure how ActiveMQ is exposed in
JMX. By default, ActiveMQ uses the MBean server that is started by
the JVM. For more information, see:
http://activemq.apache.org/jmx.html
-->
<managementContext>
<managementContext createConnector="false"/>
</managementContext>
<!--
Configure message persistence for the broker. The default persistence
mechanism is the KahaDB store (identified by the kahaDB tag).
For more information, see:
http://activemq.apache.org/persistence.html
-->
<persistenceAdapter>
<!-- <kahaDB directory="${activemq.data}/kahadb"/> -->
<jdbcPersistenceAdapter dataDirectory="${activemq.base}/data" dataSource="#mysql-ds"/>
</persistenceAdapter>
<!--
The systemUsage controls the maximum amount of space the broker will
use before disabling caching and/or slowing down producers. For more information, see:
http://activemq.apache.org/producer-flow-control.html
-->
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage percentOfJvmHeap="70" />
</memoryUsage>
<storeUsage>
<storeUsage limit="10 gb"/>
</storeUsage>
<tempUsage>
<tempUsage limit="5 gb"/>
</tempUsage>
</systemUsage>
</systemUsage>
<!--
The transport connectors expose ActiveMQ over a given protocol to
clients and other brokers. For more information, see:
http://activemq.apache.org/configuring-transports.html
-->
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
<!-- destroy the spring context on shutdown to stop jetty -->
<shutdownHooks>
<bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
</shutdownHooks>
</broker>
<!-- MySql DataSource Setup -->
<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url"
value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
<property name="username" value="user"/>
<property name="password" value="pass"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
<!--
Enable web consoles, REST and Ajax APIs and demos
The web consoles requires by default login, you can disable this in the jetty.xml file
Take a look at ${ACTIVEMQ_HOME}/conf/jetty.xml for more details
-->
<import resource="jetty.xml"/>
</beans>
File: --> activemq.log
2015-12-15 17:34:31,411 | INFO | Refreshing org.apache.activemq.xbean.XBeanBrokerFactory$1#d799e8: startup date [Tue Dec 15 17:34:31 CET 2015]; root of context hierarchy | org.apache.activemq.xbean.XBeanBrokerFactory$1 | WrapperSimpleAppMain
2015-12-15 17:34:32,813 | WARN | Exception encountered during context initialization - cancelling refresh attempt | org.apache.activemq.xbean.XBeanBrokerFactory$1 | WrapperSimpleAppMain
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService#0' defined in class path resource [activemq.xml]: Cannot create inner bean '(inner bean)#13fdf13' of type [org.apache.activemq.store.jdbc.JDBCPersistenceAdapter] while setting bean property 'persistenceAdapter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#13fdf13' defined in class path resource [activemq.xml]: Cannot resolve reference to bean 'mysql-ds' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'mysql-ds' defined in class path resource [activemq.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:287)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1419)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:636)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934)[spring-context-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)[spring-context-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:64)[xbean-spring-3.18.jar:3.18]
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:52)[xbean-spring-3.18.jar:3.18]
at org.apache.activemq.xbean.XBeanBrokerFactory$1.<init>(XBeanBrokerFactory.java:104)[activemq-spring-5.12.1.jar:5.12.1]
at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:104)[activemq-spring-5.12.1.jar:5.12.1]
at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:67)[activemq-spring-5.12.1.jar:5.12.1]
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)[activemq-broker-5.12.1.jar:5.12.1]
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)[activemq-broker-5.12.1.jar:5.12.1]
at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:87)[activemq-console-5.12.1.jar:5.12.1]
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:62)[activemq-console-5.12.1.jar:5.12.1]
at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:154)[activemq-console-5.12.1.jar:5.12.1]
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:62)[activemq-console-5.12.1.jar:5.12.1]
at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)[activemq-console-5.12.1.jar:5.12.1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_65]
at java.lang.reflect.Method.invoke(Unknown Source)[:1.8.0_65]
at org.apache.activemq.console.Main.runTaskClass(Main.java:262)[activemq.jar:5.12.1]
at org.apache.activemq.console.Main.main(Main.java:115)[activemq.jar:5.12.1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_65]
at java.lang.reflect.Method.invoke(Unknown Source)[:1.8.0_65]
at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)[wrapper.jar:3.2.3]
at java.lang.Thread.run(Unknown Source)[:1.8.0_65]
2015-12-15 17:34:32,933 | ERROR | Failed to load: class path resource [activemq.xml], reason: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService#0' defined in class path resource [activemq.xml]: Cannot create inner bean '(inner bean)#13fdf13' of type [org.apache.activemq.store.jdbc.JDBCPersistenceAdapter] while setting bean property 'persistenceAdapter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#13fdf13' defined in class path resource [activemq.xml]: Cannot resolve reference to bean 'mysql-ds' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'mysql-ds' defined in class path resource [activemq.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource | org.apache.activemq.xbean.XBeanBrokerFactory | WrapperSimpleAppMain
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.activemq.xbean.XBeanBrokerService#0' defined in class path resource [activemq.xml]: Cannot create inner bean '(inner bean)#13fdf13' of type [org.apache.activemq.store.jdbc.JDBCPersistenceAdapter] while setting bean property 'persistenceAdapter'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#13fdf13' defined in class path resource [activemq.xml]: Cannot resolve reference to bean 'mysql-ds' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.commons.dbcp.BasicDataSource] for bean with name 'mysql-ds' defined in class path resource [activemq.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:287)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:129)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1419)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1160)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:636)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:934)[spring-context-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)[spring-context-3.2.11.RELEASE.jar:3.2.11.RELEASE]
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:64)[xbean-spring-3.18.jar:3.18]
at org.apache.xbean.spring.context.ResourceXmlApplicationContext.<init>(ResourceXmlApplicationContext.java:52)[xbean-spring-3.18.jar:3.18]
at org.apache.activemq.xbean.XBeanBrokerFactory$1.<init>(XBeanBrokerFactory.java:104)[activemq-spring-5.12.1.jar:5.12.1]
at org.apache.activemq.xbean.XBeanBrokerFactory.createApplicationContext(XBeanBrokerFactory.java:104)[activemq-spring-5.12.1.jar:5.12.1]
at org.apache.activemq.xbean.XBeanBrokerFactory.createBroker(XBeanBrokerFactory.java:67)[activemq-spring-5.12.1.jar:5.12.1]
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:71)[activemq-broker-5.12.1.jar:5.12.1]
at org.apache.activemq.broker.BrokerFactory.createBroker(BrokerFactory.java:54)[activemq-broker-5.12.1.jar:5.12.1]
at org.apache.activemq.console.command.StartCommand.runTask(StartCommand.java:87)[activemq-console-5.12.1.jar:5.12.1]
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:62)[activemq-console-5.12.1.jar:5.12.1]
at org.apache.activemq.console.command.ShellCommand.runTask(ShellCommand.java:154)[activemq-console-5.12.1.jar:5.12.1]
at org.apache.activemq.console.command.AbstractCommand.execute(AbstractCommand.java:62)[activemq-console-5.12.1.jar:5.12.1]
at org.apache.activemq.console.command.ShellCommand.main(ShellCommand.java:104)[activemq-console-5.12.1.jar:5.12.1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_65]
at java.lang.reflect.Method.invoke(Unknown Source)[:1.8.0_65]
at org.apache.activemq.console.Main.runTaskClass(Main.java:262)[activemq.jar:5.12.1]
at org.apache.activemq.console.Main.main(Main.java:115)[activemq.jar:5.12.1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)[:1.8.0_65]
at java.lang.reflect.Method.invoke(Unknown Source)[:1.8.0_65]
at org.tanukisoftware.wrapper.WrapperSimpleApp.run(WrapperSimpleApp.java:240)[wrapper.jar:3.2.3]
at java.lang.Thread.run(Unknown Source)[:1.8.0_65]
Could you please help me fixing this problem?
ActiveMQ ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
Have a look in your activemq/lib/optional folder. If you have commons-dbcp2 jar instead of commons-dbcp, change the bean of your datasource class from
<bean id="oracle-ds" class="org.apache.commons.dbcp.BasicDataSource"
to
<bean id="oracle-ds" class="org.apache.commons.dbcp2.BasicDataSource"
Bit annoying that on the ActiveMQ site it's JDBC example is still using the old class
You are missing org.apache.commons.dbcp.BasicDataSource
which causes:
java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:287)[spring-beans-3.2.11.RELEASE.jar:3.2.11.RELEASE]
You are missing following jar in your class path: commons-dbcp-1.2.2.jar
You can download it from here: https://commons.apache.org/proper/commons-dbcp/download_dbcp.cgi
I am using WildFly 8.2 and setup the following external context
<subsystem xmlns="urn:jboss:domain:naming:2.0">
<bindings>
<external-context name="java:global/ldap" module="org.jboss.as.naming" class="javax.naming.ldap.InitialLdapContext" cache="true">
<environment>
<property name="java.naming.factory.initial" value="com.sun.jndi.ldap.LdapCtxFactory"/>
<property name="java.naming.provider.url" value="ldap://example.com:389"/>
<property name="java.naming.security.authentication" value="simple"/>
<property name="java.naming.security.principal" value="CN=exampleuser,DC=example,DC=com"/>
<property name="java.naming.security.credentials" value="examplepassword"/>
</environment>
</external-context>
</bindings>
<remote-naming/>
</subsystem>
I am trying to use this external context to connect to Active Directory with this code:
#Resource(lookup = "java:global/ldap")
private LdapContext ldapCtx;
NamingEnumeration<SearchResult> enumeration = ldapCtx.search();
I get the following errors:
Caused by: java.lang.IllegalArgumentException: JBAS016081: Error injecting resource into CDI managed bean. Can't find a resource named java:global/ldap defined on private javax.naming.ldap.LdapContext com.example.LdapClient.ldapCtx
If I change my code to
#Resource(lookup = "java:global/ldap")
private InitialDirContext iniCtx;
LdapContext ldapCtx = (LdapContext) iniCtx;
NamingEnumeration<SearchResult> enumeration = ldapCtx.search();
I get
Caused by: javax.naming.NamingException: JBAS011878: Failed to lookup ldap [Root exception is java.lang.RuntimeException: java.lang.NoSuchMethodException: javax.naming.ldap.LdapContext.<init>(java.util.Hashtable)]
Looks like you've set the class for your context to the LdapContext interface in the naming subsystem. I believe (and please correct me if I'm wrong as it's been a while since I've done any work with this aspect) this needs to be an actual implementation class, i.e., InitialDirContext, InitialLdapContext, etc. You'll then need to modify your #Resource injection accordingly.
I would have preferred to make this a comment, but not enough points. :)
I am working on a number of spring projects that was using C3P0 for database pooling.
My firm is moving to JBoss and we are going to be using JBoss JNDI Datasources. But how do I setup my XML files so I can still run my JUnit Testing?
I change my database xml to have the following lines:
<jee:jndi-lookup id="os400dataSource" jndi-name="java:jboss/datasources/as400"
expected-type="javax.sql.DataSource" />
and the project runs great within JBoss AS7 but to do my build with maven and to run the junit test I can't get it to ass the datasource in jboss?
I am getting the following error with junit test now:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'os400dataSource': Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:587)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:925)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:472)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
... 24 more
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 38 more