org.springframework.beans.factory.BeanCreationException:创建名为'mvcValidator'的bean时出错

时间:2018-05-25 09:36:06

标签: spring-boot

我刚才是Spring Boot的新手,我尝试使用最简单的Spring启动Web应用程序

  

“Hello World”

jsp页面。

但我得到的例外情况如下

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mvcValidator' defined in class org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658) ~[spring-webmvc-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:530) ~[spring-webmvc-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484) ~[spring-webmvc-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136) [spring-webmvc-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at javax.servlet.GenericServlet.init(GenericServlet.java:158) [servlet-api.jar:3.1.FR]
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1144) [catalina.jar:8.5.29]
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:986) [catalina.jar:8.5.29]
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4939) [catalina.jar:8.5.29]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5249) [catalina.jar:8.5.29]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:8.5.29]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1421) [catalina.jar:8.5.29]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1411) [catalina.jar:8.5.29]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_162]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_162]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_162]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_162]
Caused by: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.jboss.logging.Slf4jLoggerProvider.getLogger(Slf4jLoggerProvider.java:29) ~[jboss-logging-3.1.3.GA.jar:3.1.3.GA]
    at org.jboss.logging.LoggerProviders.find(LoggerProviders.java:33) ~[jboss-logging-3.1.3.GA.jar:3.1.3.GA]
    at org.jboss.logging.LoggerProviders.<clinit>(LoggerProviders.java:28) ~[jboss-logging-3.1.3.GA.jar:3.1.3.GA]
    at org.jboss.logging.Logger.getLogger(Logger.java:2163) ~[jboss-logging-3.1.3.GA.jar:3.1.3.GA]
    at org.jboss.logging.Logger$1.run(Logger.java:2263) ~[jboss-logging-3.1.3.GA.jar:3.1.3.GA]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_162]
    at org.jboss.logging.Logger.getMessageLogger(Logger.java:2227) ~[jboss-logging-3.1.3.GA.jar:3.1.3.GA]
    at org.jboss.logging.Logger.getMessageLogger(Logger.java:2214) ~[jboss-logging-3.1.3.GA.jar:3.1.3.GA]
    at org.hibernate.validator.internal.util.logging.LoggerFactory.make(LoggerFactory.java:29) ~[hibernate-validator-5.1.3.Final.jar:5.1.3.Final]
    at org.hibernate.validator.internal.util.Version.<clinit>(Version.java:27) ~[hibernate-validator-5.1.3.Final.jar:5.1.3.Final]
    at org.hibernate.validator.internal.engine.ConfigurationImpl.<clinit>(ConfigurationImpl.java:66) ~[hibernate-validator-5.1.3.Final.jar:5.1.3.Final]
    at org.hibernate.validator.HibernateValidator.createGenericConfiguration(HibernateValidator.java:41) ~[hibernate-validator-5.1.3.Final.jar:5.1.3.Final]
    at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:276) ~[validation-api-1.1.0.Final.jar:na]
    at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:223) ~[spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.validation.beanvalidation.OptionalValidatorFactoryBean.afterPropertiesSet(OptionalValidatorFactoryBean.java:40) ~[spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
    ... 25 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291) ~[catalina.jar:8.5.29]
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119) ~[catalina.jar:8.5.29]
    ... 42 common frames omitted

我的简单java文件位于

之下
package com.config;

@SpringBootApplication(scanBasePackages = {"com.config"})   
public class EaSiSamApplication extends SpringBootServletInitializer{

    public static void main(String[] args) {
        SpringApplication.run(EaSiSamApplication.class, args);
    }

    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(EaSiSamApplication.class);
    }
}

我的控制器如下     包com.config.controller

@Controller
public class Login {

    @RequestMapping("/")
    public String login() {
        return "login";
    }
}

我保留了我的

  

的login.jsp

在src / main / resource-&gt; templates-&gt; login.jsp

在上面运行代码时,我正在 404

请帮我摆脱这个问题。我在网上得到了很多有用的教程,但我很想知道我的错。

2 个答案:

答案 0 :(得分:0)

检查你是否在项目中升级了slf4j-api.jar。

答案 1 :(得分:0)

只需将tomcat7替换为tomcat9即可解决此问题。