2015-01-09 32 views
5

Próbuję użyć właściwości JNDI, aby ustawić Spring za pomocą adnotacji do połączenia z bazą danych. mogę ustawić server.xmlUstawianie połączenia JNDI ze sprężyną za pomocą adnotacji

<Resource name="jdbc/cms" 
      global="jdbc/cms" 
      auth="Container" 
      type="javax.sql.DataSource" 
      driverClassName="com.mysql.jdbc.Driver" 
      url="jdbc:mysql://localhost:3306/cms" 
      username="root" 
      password="admin" 
      maxActive="100" 
      maxIdle="20" 
      minIdle="5" 
      maxWait="10000"/> 

context.xml

<ResourceLink name="jdbc/cms" 
        global="jdbc/cms" 
        auth="Container" 
        type="javax.sql.DataSource" /> 

DispatcherServlet

public class Dispatcher implements WebApplicationInitializer { 

    @Override 
    public void onStartup(ServletContext servletContext) throws ServletException{ 
     AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); 
     appContext.register(ApplicationContext.class); 
     ServletRegistration.Dynamic dispatcher = servletContext.addServlet("SpringDispatcher", new DispatcherServlet(appContext)); 
     dispatcher.setLoadOnStartup(1); 
     dispatcher.addMapping("/"); 
    } 
} 

appicationContext

@Configuration 
@ComponentScan("com.myproject") 
@EnableTransactionManagement 
public class ApplicationContext { 

    @Bean(name="dataSource") 
    @Resource(name="jdbc/cms") 
    public DataSource getDataSource(){ 
     JndiDataSourceLookup dsLookup = new JndiDataSourceLookup(); 
     dsLookup.setResourceRef(true); 
     DataSource dataSource = dsLookup.getDataSource("java:comp/env/jdbc/cms"); 
     return dataSource; 
    } 
} 

gdy próbuję uruchomić mój projekt widzę jes s rzeczy:

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSourceLookup' threw exception; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/cms'; nested exception is javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) 
    ... 27 more 
Caused by: org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/cms'; nested exception is javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:48) 
    at com.myproject.resolvers.ApplicationContext.dataSourceLookup(ApplicationContext.java:30) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f.CGLIB$dataSourceLookup$1(<generated>) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f$$FastClassBySpringCGLIB$$a70a8bf4.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f.dataSourceLookup(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
    ... 28 more 
Caused by: javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:820) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:168) 
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158) 
    at javax.naming.InitialContext.lookup(InitialContext.java:411) 
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) 
    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:179) 
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) 
    at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:45) 
    ... 39 more 

Jan 09, 2015 2:39:27 PM org.springframework.web.servlet.DispatcherServlet initServletBean 
SEVERE: Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceLookup' defined in com.myproject.resolvers.ApplicationContext: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSourceLookup' threw exception; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/cms'; nested exception is javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663) 
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:535) 
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489) 
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 
    at javax.servlet.GenericServlet.init(GenericServlet.java:160) 
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) 
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1091) 
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSourceLookup' threw exception; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/cms'; nested exception is javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) 
    ... 27 more 
Caused by: org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/cms'; nested exception is javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:48) 
    at com.myproject.resolvers.ApplicationContext.dataSourceLookup(ApplicationContext.java:30) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f.CGLIB$dataSourceLookup$1(<generated>) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f$$FastClassBySpringCGLIB$$a70a8bf4.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f.dataSourceLookup(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
    ... 28 more 
Caused by: javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:820) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:168) 
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158) 
    at javax.naming.InitialContext.lookup(InitialContext.java:411) 
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) 
    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:179) 
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) 
    at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:45) 
    ... 39 more 

Jan 09, 2015 2:39:27 PM org.apache.catalina.core.ApplicationContext log 
SEVERE: StandardWrapper.Throwable 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceLookup' defined in com.myproject.resolvers.ApplicationContext: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSourceLookup' threw exception; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/cms'; nested exception is javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663) 
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:535) 
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489) 
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 
    at javax.servlet.GenericServlet.init(GenericServlet.java:160) 
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) 
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1091) 
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSourceLookup' threw exception; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/cms'; nested exception is javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) 
    ... 27 more 
Caused by: org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'java:comp/env/jdbc/cms'; nested exception is javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:48) 
    at com.myproject.resolvers.ApplicationContext.dataSourceLookup(ApplicationContext.java:30) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f.CGLIB$dataSourceLookup$1(<generated>) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f$$FastClassBySpringCGLIB$$a70a8bf4.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f.dataSourceLookup(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
    ... 28 more 
Caused by: javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:820) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:168) 
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158) 
    at javax.naming.InitialContext.lookup(InitialContext.java:411) 
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) 
    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:179) 
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) 
    at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:45) 
    ... 39 more 

Jan 09, 2015 2:39:27 PM org.apache.catalina.core.StandardContext loadOnStartup 
SEVERE: Servlet /ApplicationAnnotations threw load() exception 
javax.naming.NameNotFoundException: Name [jdbc/cms] is not bound in this Context. Unable to find [jdbc]. 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:820) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:154) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:831) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:168) 
    at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158) 
    at javax.naming.InitialContext.lookup(InitialContext.java:411) 
    at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) 
    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:179) 
    at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95) 
    at org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:45) 
    at com.myproject.resolvers.ApplicationContext.dataSourceLookup(ApplicationContext.java:30) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f.CGLIB$dataSourceLookup$1(<generated>) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f$$FastClassBySpringCGLIB$$a70a8bf4.invoke(<generated>) 
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) 
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309) 
    at com.myproject.resolvers.ApplicationContext$$EnhancerBySpringCGLIB$$beebf90f.dataSourceLookup(<generated>) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) 
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1111) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1006) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:762) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480) 
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663) 
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:535) 
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489) 
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) 
    at javax.servlet.GenericServlet.init(GenericServlet.java:160) 
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280) 
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1091) 
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5176) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5460) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:745) 

Co może być problemem?

aktualizacja

@Bean(name="dataSource") 
public DataSource dataSourceLookup() { 
    JndiDataSourceLookup dsLookup = new JndiDataSourceLookup(); 
    DataSource dataSource = dsLookup.getDataSource("jdbc/cms"); 
    return dataSource; 
} 

wyjątek to samo ponownie

aktualizacja

<resource-ref> 
    <description>DB Connection</description> 
    <res-ref-name>jdbc/cms</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

działać poprzez właściwości web.xml, ale jak to zrobić za pomocą twardego kodowania nadal jest Tajemnica ... Nie chcę w to wierzyć

+1

najpierw usunąć '@ Resource' to nie ma sensu. Nie musisz robić 'setResourceRef (true)', ponieważ jest to ustawienie domyślne i po prostu spróbuj użyć 'jdbc/jms' zamiast tego, spring doda" java: comp/env/"i spróbuje normalnej nazwy. –

+0

@Bean (name = "DataSource") \t DataSource publicznego dataSourceLookup() { \t \t JndiDataSourceLookup dsLookup = new JndiDataSourceLookup(); \t \t DataSource dataSource = dsLookup.getDataSource ("jdbc/cms"); \t \t return dataSource; \t} – alemale

+0

To musi wyglądać tak? ale błąd ten sam Jan 09, 2015 3:39:16 PM org.apache.catalina.core.StandardContext loadOnStartup KOD: Serwlet/ApplicationAnnotations rzucił wyjątek load() javax.naming.NameNotFoundException: Nazwa [jdbc/cms] nie jest związany w tym kontekście. Nie można znaleźć [jdbc]. – alemale

Odpowiedz

1

spróbuj dodać następujące wpisy do pom -

<dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.17</version> 
    </dependency>