I'm trying to run Spring. Download an application that works fine in Tomcat 7.
The error I get is ...
2016-12-12 10:38:48.224 ERROR 1248 --- [ main] org.apache.ibatis.executor.BaseExecutor : Could not get a databaseId from dataSource
org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; 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.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:142) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:192) ~[spring-aop-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
at com.sun.proxy.$Proxy52.getConnection(Unknown Source) ~[na:na]
at org.apache.ibatis.mapping.VendorDatabaseIdProvider.getDatabaseProductName(VendorDatabaseIdProvider.java:76) ~[mybatis-3.2.3.jar!/:3.2.3]
at org.apache.ibatis.mapping.VendorDatabaseIdProvider.getDatabaseName(VendorDatabaseIdProvider.java:61) ~[mybatis-3.2.3.jar!/:3.2.3]
at org.apache.ibatis.mapping.VendorDatabaseIdProvider.getDatabaseId(VendorDatabaseIdProvider.java:49) ~[mybatis-3.2.3.jar!/:3.2.3]
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:449) [mybatis-spring-1.2.1.jar!/:1.2.1]
at org.mybatis.spring.SqlSessionFactoryBean.afterPropertiesSet(SqlSessionFactoryBean.java:340) [mybatis-spring-1.2.1.jar!/:1.2.1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) [spring-beans-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
<SNIP>
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.7.0_80]
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) ~[na:1.7.0_80]
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344) ~[na:1.7.0_80]
at javax.naming.InitialContext.lookup(InitialContext.java:411) ~[na:1.7.0_80]
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
at org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:135) ~[spring-context-4.3.4.RELEASE.jar!/:4.3.4.RELEASE]
<SNIP>
2016-12-12 10:38:50.850 INFO 1248 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationGlobalProperties' of type [class org.springframework.beans.factory.config.PropertiesFactoryBean] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-12-12 10:38:50.863 INFO 1248 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationGlobalProperties' of type [class java.util.Properties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-12-12 10:38:51.543 WARN 1248 --- [ main] hello.Application : ******************************************************* postProcessContext
2016-12-12 10:38:51.547 WARN 1248 --- [ main] hello.Application : ******************************************************* getTomcatEmbeddedServletContainer
2016-12-12 10:38:51.556 INFO 1248 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
I have a tomcat factory, but it only starts after the stack trace above. (See the last section of the log file above)
@Bean public TomcatEmbeddedServletContainerFactory tomcatFactory () {return new TomcatEmbeddedServletContainerFactory () {
@Override
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) {
LOG.warn(" ******************************************************* getTomcatEmbeddedServletContainer");
tomcat.enableNaming();
return super.getTomcatEmbeddedServletContainer(tomcat);
}
@Override
protected void postProcessContext(Context context) {
LOG.warn(" ******************************************************* postProcessContext");
ContextResource resourceDB1 = new ContextResource();
resourceDB1.setName("jdbc/DB");
resourceDB1.setType(DataSource.class.getName());
resourceDB1.setProperty("driverClassName", "com.ibm.db2.jcc.DB2Driver");
resourceDB1.setProperty("url", "jdbc:db2://localhost:51000/cdb:deferPrepares=false;");
resourceDB1.setProperty("username", "xxx");
resourceDB1.setProperty("password", "xxx");
context.getNamingResources().addResource(resourceDB1);
}
};
}
Can someone advise you how I can solve the above error.
source
share