问题描述
我试图用maven2管理的依赖设置webapp。在这里,我的pom.xml
< project xmlns =http://maven.apache.org/POM/4.0.0 xmlns:xsi =http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache。组织/行家-v4_0_0.xsd>
< modelVersion> 4.0.0< / modelVersion>
< groupId> mtx-production< / groupId>
< artifactId> mtx-production< / artifactId>
< version> 0.0.1< / version>
<依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-core< / artifactId>
< version> 3.0.2.RELEASE< / version>
< /依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-orm< / artifactId>
< version> 3.0.2.RELEASE< / version>
< type> jar< / type>
< /依赖关系>
< dependency>
< groupId> org.springframework< / groupId>
< artifactId> spring-web< / artifactId>
< version> 3.0.2.RELEASE< / version>
< type> jar< / type>
< /依赖关系>
< dependency>
< groupId> mysql< / groupId>
< artifactId> mysql-connector-java< / artifactId>
< version> 5.1.12< / version>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-core< / artifactId>
< version> 3.5.1-最终< / version>
< type> jar< / type>
< scope>编译< / scope>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-annotations< / artifactId>
< version> 3.5.1-最终< / version>
< type> jar< / type>
< scope>编译< / scope>
< /依赖关系>
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-log4j12< / artifactId>
< version> 1.5.8< / version>
< type> jar< / type>
< scope>编译< / scope>
< /依赖关系>
< dependency>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.14< / version>
< type> jar< / type>
< scope>编译< / scope>
< /依赖关系>
< /依赖关系>
< repositories>
< repository>
< id> jboss-releases< / id>
< url> http://repository.jboss.org/maven2< / url>
< / repository>
< / repositories>
< / project>
如果我有什么问题,请纠正我的错误,但这应该起作用?!我只在eclipse中得到这个异常
13.06.2010 16:48:15 org.springframework.context.support.AbstractApplicationContext $ BeanPostProcessorChecker postProcessAfterInitialization
产品介绍:豆数据源是没有资格给所有BeanPostProcessor的越来越处理(例如:自动代理不符合资格)
SLF4J:无法加载类org.slf4j.impl.StaticLoggerBinder 。
SLF4J:有关详细信息,请参阅http://www.slf4j.org/codes.html#StaticLoggerBinder。
2010年6月13日十六点48分15秒org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
产品介绍:在org.springframework.beans.factory.support.DefaultListableBeanFactory@366573销毁单身:定义豆[ org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor, org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,数据源,SessionFactory对象,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,#org.springframework.transaction.interceptor.TransactionInterceptor 0,org.springframework.transaction.config.internalTransactionAdv ISOR,myTxManager,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0];工厂层次
2010年6月13日16时48分15秒的根org.springframework.web.context.ContextLoader initWebApplicationContext
SCHWERWIEGEND:上下文初始化失败
org.springframework.beans.factory.BeanCreationException:错误在ServletContext资源中定义名为'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0'的bean [/WEB-INF/applicationContext.xml]:bean初始化失败;嵌套异常是org.springframework.beans.factory.BeanCreationException:在ServletContext资源[/WEB-INF/applicationContext.xml]中定义名称为'sessionFactory'的Bean时创建错误:调用init方法失败;嵌套的异常是java.lang.NoClassDefFoundError:org.springframework上的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
中的org / slf4j / impl / StaticLoggerBinder
。 beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:291)
at org.springframework .beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework .beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
在org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplica tionContext.java:687)在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:408
)
在org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197 276)
)
。在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)$ b在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
$ b在org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
。在组织.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
在org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
在org.apache.catalina .core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(Sta ndardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java: 710)
在org.apache.catalina.startup.Catalina.start(Catalina.java:566)
在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
。在sun.reflect。 NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
在java.lang.reflect.Method.invoke(Method.java:597)在org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
在org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
引起:org.springframework.beans.factory.BeanCreationException:在ServletContext资源[/WEB-INF/applicationContext.xml]中定义名称为'sessionFactory'的Bean时创建错误:调用init方法失败ED;嵌套的异常是java.lang.NoClassDefFoundError:org.springframework上的org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
中的org / slf4j / impl / StaticLoggerBinder
。在org.springframework上
。org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
在org.springframework。
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework。 beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework .beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)$ or
at org.springframework.beans.factory.support.AbstractBeanFactory.getBe (org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors($))中的
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor。< init>(PersistenceExceptionTranslationInterceptor .java:79)
at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor。< init>(PersistenceExceptionTranslationAdvisor.java:70)
at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor。 java:99)
在org.springframework.beans.factory.su pport.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1431)
处org.springframework.beans.factory org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1400)
。 support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 25更
。通过引起:java.lang.NoClassDefFoundError:组织/ SLF4J / IMPL / StaticLoggerBinder
我的设置出了什么问题?
在你的依赖中包含slf4j-api:
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-api< / artifactId>
< version> 1.5.8< / version>
< /依赖关系>
排除commons-logging依赖关系,为您声明的最小弹簧依赖关系之一提供slf4j facade for commons -logging:
<依赖关系>
< groupId> org.springframework< / groupId>
< artifactId> spring-context< / artifactId>
< version> 3.0.2.RELEASE< / version>
<排除项>
<排除>
< groupId> commons-logging< / groupId>
< artifactId> commons-logging< / artifactId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> jcl-over-slf4j< / artifactId>
< version> 1.5.8< / version>
< scope>运行时< / scope>
< /依赖关系>
包含您的日志记录的log4j依赖项以及slf4j外观:
< dependency>
< groupId> org.slf4j< / groupId>
< artifactId> slf4j-log4j12< / artifactId>
< version> 1.5.8< / version>
< scope>运行时< / scope>
< /依赖关系>
< dependency>
< groupId> log4j< / groupId>
< artifactId> log4j< / artifactId>
< version> 1.2.14< / version>
< scope>运行时< / scope>
< /依赖关系>
SpringSource Team blog中提供了一篇关于使用SLF4J和Spring进行日志记录的完美博客文章根据。
I'm trying to setup a webapp with maven2 managed dependcies. Here my pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mtx-production</groupId>
<artifactId>mtx-production</artifactId>
<version>0.0.1</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.0.2.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.0.2.RELEASE</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.12</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.5.1-Final</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.1-Final</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jboss-releases</id>
<url>http://repository.jboss.org/maven2</url>
</repository>
</repositories>
</project>
Correct me if I got something wrong but this should work?! I only getting in my eclipse this exception
13.06.2010 16:48:15 org.springframework.context.support.AbstractApplicationContext$BeanPostProcessorChecker postProcessAfterInitialization
INFO: Bean 'dataSource' is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
13.06.2010 16:48:15 org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@366573: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,sessionFactory,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,myTxManager,org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0]; root of factory hierarchy
13.06.2010 16:48:15 org.springframework.web.context.ContextLoader initWebApplicationContext
SCHWERWIEGEND: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor#0' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:408)
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3830)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4337)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
at org.apache.catalina.core.StandardService.start(StandardService.java:516)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
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:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:387)
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:266)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:79)
at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:70)
at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:99)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1431)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1400)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
... 25 more
Caused by: java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder
What is wrong with my setup?
Include the slf4j-api in your dependencies:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
Exclude the commons-logging dependency for minimum one of your declared spring dependencies and provide the slf4j facade for commons-logging:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.5.8</version>
<scope>runtime</scope>
</dependency>
Include the log4j dependency for your logging together with the slf4j facade:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.8</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
<scope>runtime</scope>
</dependency>
A great blog post for further reading about logging with SLF4J and Spring can be found in the SpringSource Team blog under http://blog.springsource.com/2009/12/04/logging-dependencies-in-spring/.
这篇关于Hibernate,Spring和SLF4J绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!