Spring启动配置tomcat context.xml数据源

时间:2015-07-28 17:45:58

标签: tomcat spring-boot datasource

我创建了一个context.xml并使用我的数据源输入/ src / main / resources:

<?xml version="1.0" encoding="UTF-8"?>
    <Context cookies="true">
        <Resource name="BeanManager"
            auth="Container"
            type="javax.enterprise.inject.spi.BeanManager"
            factory="org.jboss.weld.resources.ManagerObjectFactory" />

  <Resource
    name="jdbc/PortalServicos"
    auth="Container"
    type="javax.sql.DataSource"
    driverClassName="org.postgresql.Driver"
    url="jdbc:postgresql://localhost:5432/portalservicos"
    username="user"
    password="pass"
    removeAbandoned="true"
    logAbandoned="true" />
</Context>

并输入我的application.properties

spring.datasource.jndi-name=java:/comp/env/jdbc/ConectorPortalServicos

但是当我尝试跑步时我得到了这个错误:

  

线程中的异常&#34; main&#34;   org.springframework.beans.factory.BeanCreationException:错误   用名字创建bean   &#39; org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration&#39 ;:   注入自动连接的依赖项失败;嵌套异常是   org.springframework.beans.factory.BeanCreationException:不能   autowire字段:private javax.sql.DataSource   org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource;   嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   创建名为&#39; dataSource&#39;的bean在类路径资源中定义   [组织/ springframework的/引导/自动配置/ JDBC / JndiDataSourceAutoConfiguration.class]:   通过工厂方法进行Bean实例化失败;嵌套异常是   org.springframework.beans.BeanInstantiationException:失败   实例化[javax.sql.DataSource]:工厂方法&#39; dataSource&#39;扔   例外;嵌套异常是   org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException:   无法使用名称查找JNDI DataSource   &#39;的java:/ comp / env的/ JDBC / ConectorPortalServicos&#39 ;;嵌套异常是   javax.naming.NoInitialContextException:需要在中指定类名   环境或系统属性,或作为applet参数,或在   应用程序资源文件:java.naming.factory.initial at   org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)     在   org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:303)     在   org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)     在   org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)     在   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)     在   org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:368)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)     在   org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:303)     在   org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)     在   org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)     在   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)     在   org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)     在   org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)     在   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)     在   org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)     在   org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:320)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:957)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:946)     在br.com.lumera.Application.main(Application.java:16)引起:   org.springframework.beans.factory.BeanCreationException:不能   autowire字段:private javax.sql.DataSource   org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource;   嵌套异常是   org.springframework.beans.factory.BeanCreationException:错误   创建名为&#39; dataSource&#39;的bean在类路径资源中定义   [组织/ springframework的/引导/自动配置/ JDBC / JndiDataSourceAutoConfiguration.class]:   通过工厂方法进行Bean实例化失败;嵌套异常是   org.springframework.beans.BeanInstantiationException:失败   实例化[javax.sql.DataSource]:工厂方法&#39; dataSource&#39;扔   例外;嵌套异常是   org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException:   无法使用名称查找JNDI DataSource   &#39;的java:/ comp / env的/ JDBC / ConectorPortalServicos&#39 ;;嵌套异常是   javax.naming.NoInitialContextException:需要在中指定类名   环境或系统属性,或作为applet参数,或在   应用程序资源文件:java.naming.factory.initial at   org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)     在   org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)     在   org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)     ... 25更多引起:   org.springframework.beans.factory.BeanCreationException:错误   创建名为&#39; dataSource&#39;的bean在类路径资源中定义   [组织/ springframework的/引导/自动配置/ JDBC / JndiDataSourceAutoConfiguration.class]:   通过工厂方法进行Bean实例化失败;嵌套异常是   org.springframework.beans.BeanInstantiationException:失败   实例化[javax.sql.DataSource]:工厂方法&#39; dataSource&#39;扔   例外;嵌套异常是   org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException:   无法使用名称查找JNDI DataSource   &#39;的java:/ comp / env的/ JDBC / ConectorPortalServicos&#39 ;;嵌套异常是   javax.naming.NoInitialContextException:需要在中指定类名   环境或系统属性,或作为applet参数,或在   应用程序资源文件:java.naming.factory.initial at   org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1014)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)     在   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)     在   org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:303)     在   org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)     在   org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)     在   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)     在   org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1120)     在   org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1044)     在   org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)     在   org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor $ AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)     ... 27更多引起:   org.springframework.beans.BeanInstantiationException:失败   实例化[javax.sql.DataSource]:工厂方法&#39; dataSource&#39;扔   例外;嵌套异常是   org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException:   无法使用名称查找JNDI DataSource   &#39;的java:/ comp / env的/ JDBC / ConectorPortalServicos&#39 ;;嵌套异常是   javax.naming.NoInitialContextException:需要在中指定类名   环境或系统属性,或作为applet参数,或在   应用程序资源文件:java.naming.factory.initial at   org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)     在   org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)     ... 39更多引起:   org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException:   无法使用名称查找JNDI DataSource   &#39;的java:/ comp / env的/ JDBC / ConectorPortalServicos&#39 ;;嵌套异常是   javax.naming.NoInitialContextException:需要在中指定类名   环境或系统属性,或作为applet参数,或在   应用程序资源文件:java.naming.factory.initial at   org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:48)     在   org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration.dataSource(JndiDataSourceAutoConfiguration.java:58)     在   org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration $$ EnhancerBySpringCGLIB $$ 9eb06593.CGLIB $ $数据源0()     在   org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration $$ EnhancerBySpringCGLIB $$ 9eb06593 $$ FastClassBySpringCGLIB $$ e2fbd35a.invoke()     在   org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)     在   org.springframework.context.annotation.ConfigurationClassEnhancer $ BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)     在   org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration $$ EnhancerBySpringCGLIB $$ 9eb06593.dataSource()     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:497)at   org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)     ... 40更多引起:javax.naming.NoInitialContextException:需要   在环境或系统属性中指定类名,或者作为   applet参数,或在应用程序资源文件中:   java.naming.factory.initial at   javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)     在   javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)     在   javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)     在javax.naming.InitialContext.lookup(InitialContext.java:417)at   org.springframework.jndi.JndiTemplate $ 1.doInContext(JndiTemplate.java:155)     在   org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)     在   org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)     在   org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)     在   org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)     在   org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup.getDataSource(JndiDataSourceLookup.java:45)     ... 51更多

0 个答案:

没有答案