2013-10-13 12 views
0

我放置META-INF(在WEB-INF的相同的深度文件夾)/ context.xml中無法獲取的Tomcat定義一個數據源

<Context path="/checchin" docBase="webapps/checchin"> 
    <Resource name="jdbc/ChecchinDB" auth="Container" type="javax.sql.DataSource" 
     maxActive="100" maxIdle="30" maxWait="10000" username="root" 
     password="redhat81" driverClassName="com.mysql.jdbc.Driver" 
     url="jdbc:mysql://localhost:3306/chechin" /> 
</Context> 

內部此代碼,然後我放置

<resource-ref> 
    <description>mySQL Datasource</description> 
    <res-ref-name>java/ChecchinDB</res-ref-name> 
    <res-type>javax.sql.DataSource</res-type> 
    <res-auth>Container</res-auth> 
</resource-ref> 

inside web.xml

但是我不能工作了! Tomcat不會顯示關於數據源部署的任何信息,然後Spring將無法引用DS。有什麼缺失?我沒有使用tomcat的經驗......但是我想了解一下寫入指南的內容。

這裏堆棧跟蹤:

Informazioni: Destroying singletons in org.s[email protected]d3ff7a: defining beans [appConfig,multipartResolver,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.security.filterChains,org.springframework.security.filterChainProxy,org.springframework.security.web.DefaultSecurityFilterChain#0,org.springframework.security.web.DefaultSecurityFilterChain#1,org.springframework.security.web.DefaultSecurityFilterChain#2,org.springframework.security.web.DefaultSecurityFilterChain#3,org.springframework.security.web.DefaultSecurityFilterChain#4,org.springframework.security.web.PortMapperImpl#0,org.springframework.security.web.PortResolverImpl#0,org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0,org.springframework.security.authentication.ProviderManager#0,org.springframework.security.web.context.HttpSessionSecurityContextRepository#0,org.springframework.security.web.authentication.session.SessionFixationProtectionStrategy#0,org.springframework.security.web.savedrequest.HttpSessionRequestCache#0,org.springframework.security.web.access.expression.DefaultWebSecurityExpressionHandler#0,org.springframework.security.access.vote.AffirmativeBased#0,org.springframework.security.web.access.intercept.FilterSecurityInterceptor#0,org.springframework.security.web.access.DefaultWebInvocationPrivilegeEvaluator#0,org.springframework.security.authentication.AnonymousAuthenticationProvider#0,org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0,org.springframework.security.userDetailsServiceFactory,org.springframework.security.web.DefaultSecurityFilterChain#5,accessDeniedHandler,messageSource,concurrencyFilter,sas,sessionRegistry,authFilter,org.springframework.security.provisioning.InMemoryUserDetailsManager#0,org.springframework.security.authentication.dao.DaoAuthenticationProvider#0,org.springframework.security.authentication.dao.DaoAuthenticationProvider#1,org.springframework.security.authentication.DefaultAuthenticationEventPublisher#0,org.springframework.security.authenticationManager,passwordEncoder,userDetailsService,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#1,dataSource,sessionFactory,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,transactionManager]; root of factory hierarchy 
    ott 13, 2013 2:56:31 PM org.springframework.web.context.ContextLoader initWebApplicationContext 
    Grave: Context initialization failed 
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Cannot resolve reference to bean 'org.springframework.security.web.DefaultSecurityFilterChain#5' while setting bean property 'sourceList' with key [5]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.DefaultSecurityFilterChain#5': Cannot resolve reference to bean 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0' while setting constructor argument with key [3]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#0': Cannot resolve reference to bean 'org.springframework.security.authentication.ProviderManager#0' while setting bean property 'authenticationManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot resolve reference to bean 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.authentication.AuthenticationManagerFactoryBean#0': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#1' while setting constructor argument with key [1]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#1': Cannot resolve reference to bean 'userDetailsService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/security-app-context.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in ServletContext resource [/WEB-INF/persistence-context.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [ChecchinDB] is not bound in this Context. Unable to find [ChecchinDB]. 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106) 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353) 
     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1327) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1085) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:516) 
     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455) 
     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293) 
     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290) 
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192) 
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567) 
     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) 
     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) 
     at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282) 
     at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204) 
     at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) 
     at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) 
     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) 
     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(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
     at java.lang.Thread.run(Unknown Source) 

... 

    Caused by: javax.naming.NameNotFoundException: Name [ChecchinDB] is not bound in this Context. Unable to find [ChecchinDB]. 
     at org.apache.naming.NamingContext.lookup(NamingContext.java:820) 
     at org.apache.naming.NamingContext.lookup(NamingContext.java:168) 
     at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158) 
     at javax.naming.InitialContext.lookup(Unknown Source) 
     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.springframew 

ork.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:1479) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419) 
    ... 110 more 
+0

確保您複製MySQL驅動到Tomcat lib文件夾'<< >> CATALINA_BASE/lib' – 2013-10-13 13:56:21

+0

,但我沒有看到數據源的任何問題,似乎都屬於spring fw。 – 2013-10-13 13:57:13

+2

在令人難以置信的長錯誤信息的末尾是這樣的:名稱[ChecchinDB]沒有被綁定在這個上下文中。無法找到[ChecchinDB]。這只是一個猜測,但在一個地方它說java/ChhecchinDB,而在另一個地方它說jdbc/ChecchinDB。這種差異可能是問題嗎? –

回答

0

Shoudn't resource-ref.res-ref-nameResource.name是一樣的嗎?您可以使用 「的Java/ChecchinDB」 和 「JDBC/ChecchinDB」 作爲標識

+0

我糾正了參考,但我仍然可以得到這個工作;這是彈簧數據源CONF:\t <豆ID = 「數據源」 類= 「org.springframework.jndi.JndiObjectFactoryBean」> \t \t <屬性名= 「jndiName」 值= 「JDBC/ChecchinDB」/> \t – tassadar

相關問題