无法启动组件 [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/wabSpring]]。

huangapple go评论82阅读模式
英文:

Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/wabSpring]]

问题

我正试图在Tomcat上启动Spring Boot应用程序。为此,我在Tomcat上部署了WAR文件,但我遇到了`Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/wabSpring]]`错误。我在谷歌上搜索了这个问题,但没有解决方案适用于我。请告诉我为什么会出现这个错误。

我使用的是Tomcat 8.5和Spring版本2.0.6。

**WebAppInitializer.java**

    public class WebAppInitializer implements WebApplicationInitializer {
	
		@Override
		public void onStartup(ServletContext container) throws ServletException 
    {
			AnnotationConfigWebApplicationContext context = new 
    AnnotationConfigWebApplicationContext();
			context.register(AppConfig.class);
			context.setServletContext(container);
	
			ServletRegistration.Dynamic servlet = 
    container.addServlet("dispatcher", new 
         DispatcherServlet(context));
			servlet.setLoadOnStartup(1);
			servlet.addMapping("/");
		}
	}

**AppConfig.java**
  
    @Configuration
    @EnableWebMvc
    @ComponentScan(basePackages = { "com.springboot.wabit.*" })

    public class AppConfig implements WebMvcConfigurer {
 
    @Autowired
    private WebFlowConfig webFlowConfig;

	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController("/").setViewName("index");
	}

 	@Bean
	public ViewResolver viewResolver() {
		InternalResourceViewResolver resolver = new 
      InternalResourceViewResolver();
		resolver.setViewClass(JstlView.class);
		resolver.setPrefix("/WEB-INF/views/");
	   	resolver.setSuffix(".jsp");
		return resolver;
	}

	@Bean(name = "multipartResolver")
    public StandardServletMultipartResolver resolver() {
        return new StandardServletMultipartResolver();
    }
	
 	@Bean(name = "multipartResolver")
	public CommonsMultipartResolver multipartResolver() {
		CommonsMultipartResolver multipartResolver = new 
     CommonsMultipartResolver();
		multipartResolver.setMaxUploadSize(2000000);  
		return multipartResolver;
	}

  
	@Bean
	public FlowHandlerAdapter flowHandlerAdapter() {
		FlowHandlerAdapter handlerAdapter = new FlowHandlerAdapter();
		handlerAdapter.setFlowExecutor(this.webFlowConfig.flowExecutor());
		handlerAdapter.setSaveOutputToFlashScopeOnRedirect(true);
		return handlerAdapter;
	}
	
	@Bean
	public FlowHandlerMapping flowHandlerMapping() {
		FlowHandlerMapping handlerMapping = new FlowHandlerMapping();
		handlerMapping.setOrder(-1);
		handlerMapping.setFlowRegistry(this.webFlowConfig.flowRegistry());
		return handlerMapping;
	}
  
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer 
    configurer) {
		configurer.enable();
	}
	

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
        .allowedOrigins("*")
        .allowedMethods("HEAD", "GET", "PUT", "POST", "DELETE", "PATCH");
        
    }

    }

**WebFlowConfig.java**

    @Configuration
    @ComponentScan(basePackages = { "com.springboot.wabit.*" })
    public class WebFlowConfig extends AbstractFlowConfiguration {

	@Autowired
	private AppConfig AppConfig;

	@Bean
	public FlowExecutor flowExecutor() {
		return 
    getFlowExecutorBuilder(flowRegistry()).addFlowExecutionListener(new 
       SecurityFlowExecutionListener(), "*")
				.build();
	}

	@Bean
	public FlowDefinitionRegistry flowRegistry() {
		return getFlowDefinitionRegistryBuilder().setBasePath("/WEB- 
    INF/views/flows")
				.addFlowLocationPattern("/**/*-flow.xml").build();
	}

	@Bean
	public FlowBuilderServices flowBuilderServices() {
		return   
       
    getFlowBuilderServicesBuilder().
    setViewFactoryCreator(mvcViewFactoryCreator())
     .setValidator(validator()).setDevelopmentMode(true).build();
	}

	@Bean
  	public MvcViewFactoryCreator mvcViewFactoryCreator() {
		MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator();
		factoryCreator.setViewResolvers(Collections.singletonList
        (this.AppConfig.viewResolver()));
		factoryCreator.setUseSpringBeanBinding(true);
		return factoryCreator;
	}

	@Bean
	public LocalValidatorFactoryBean validator() {
		return new LocalValidatorFactoryBean();
	}

      }

**web.xml**

    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
		 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
	version="3.1">
	<display-name>Archetype Created Web Application</display-name>

 	<servlet>
		<servlet-name>dispatcher</servlet-name>
		<servlet- 
        class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

 		<init-param>
			<param-name>throwExceptionIfNoHandlerFound</param-name>
			<param-value>true</param-value>
		</init-param>

		<multipart-config>
			<max-file-size>2097152</max-file-size>
			<max-request-size>4194304</max-request-size>
			<file-size-threshold>1048576</file-size-threshold>
		</multipart-config>
	</servlet>

	<servlet-mapping>
		<servlet-name>dispatcher</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>
 
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			/WEB-INF/spring-security.xml
		</param-value>
	</context-param>
	
	<filter>
		<filter-name>springSecurityFilterChain</filter-name>
		<filter- 
    class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>springSecurityFilterChain</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

    </web-app>  

**dispatcher.xml**

    
    <beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:wf="http://www.springframework.org/schema/webflow-config"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
	
	http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/webflow-config
    http://www.springframework.org/schema/webflow-config/spring-webflow- 
    config.xsd">

	<context:component-s

<details>
<summary>英文:</summary>

I am trying to start spring boot app on tomcat.For that I deployed war file on tomcat, But I am getting `Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/wabSpring]]`. I search for this on google but no solution worked for me. Please tell me why I am getting this error.

I am using tomcat 8.5 and spring version 2.0.6

**WebAppInitializer.java**

    public class WebAppInitializer implements WebApplicationInitializer {
	
		@Override
		public void onStartup(ServletContext container) throws ServletException 
    {
			AnnotationConfigWebApplicationContext context = new 
    AnnotationConfigWebApplicationContext();
			context.register(AppConfig.class);
			context.setServletContext(container);
	
			ServletRegistration.Dynamic servlet = 
    container.addServlet(&quot;dispatcher&quot;, new 
         DispatcherServlet(context));
			servlet.setLoadOnStartup(1);
			servlet.addMapping(&quot;/&quot;);
		}
	}

**AppConfig.java**
  
    @Configuration
    @EnableWebMvc
    @ComponentScan(basePackages = { &quot;com.springboot.wabit.*&quot; })

    public class AppConfig implements WebMvcConfigurer {
 
    @Autowired
    private WebFlowConfig webFlowConfig;

	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController(&quot;/&quot;).setViewName(&quot;index&quot;);
	}

 	@Bean
	public ViewResolver viewResolver() {
		InternalResourceViewResolver resolver = new 
      InternalResourceViewResolver();
		resolver.setViewClass(JstlView.class);
		resolver.setPrefix(&quot;/WEB-INF/views/&quot;);
	   	resolver.setSuffix(&quot;.jsp&quot;);
		return resolver;
	}

	@Bean(name = &quot;multipartResolver&quot;)
    public StandardServletMultipartResolver resolver() {
        return new StandardServletMultipartResolver();
    }
	
 	@Bean(name = &quot;multipartResolver&quot;)
	public CommonsMultipartResolver multipartResolver() {
		CommonsMultipartResolver multipartResolver = new 
     CommonsMultipartResolver();
		multipartResolver.setMaxUploadSize(2000000);  
		return multipartResolver;
	}

  
	@Bean
	public FlowHandlerAdapter flowHandlerAdapter() {
		FlowHandlerAdapter handlerAdapter = new FlowHandlerAdapter();
		handlerAdapter.setFlowExecutor(this.webFlowConfig.flowExecutor());
		handlerAdapter.setSaveOutputToFlashScopeOnRedirect(true);
		return handlerAdapter;
	}
	
	@Bean
	public FlowHandlerMapping flowHandlerMapping() {
		FlowHandlerMapping handlerMapping = new FlowHandlerMapping();
		handlerMapping.setOrder(-1);
		handlerMapping.setFlowRegistry(this.webFlowConfig.flowRegistry());
		return handlerMapping;
	}
  
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer 
    configurer) {
		configurer.enable();
	}
	

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping(&quot;/**&quot;)
        .allowedOrigins(&quot;*&quot;)
        .allowedMethods(&quot;HEAD&quot;, &quot;GET&quot;, &quot;PUT&quot;, &quot;POST&quot;, &quot;DELETE&quot;, &quot;PATCH&quot;);
        
    }

    }

**WebFlowConfig.java**

    @Configuration
    @ComponentScan(basePackages = { &quot;com.springboot.wabit.*&quot; })
    public class WebFlowConfig extends AbstractFlowConfiguration {

	@Autowired
	private AppConfig AppConfig;

	@Bean
	public FlowExecutor flowExecutor() {
		return 
    getFlowExecutorBuilder(flowRegistry()).addFlowExecutionListener(new 
       SecurityFlowExecutionListener(), &quot;*&quot;)
				.build();
	}

	@Bean
	public FlowDefinitionRegistry flowRegistry() {
		return getFlowDefinitionRegistryBuilder().setBasePath(&quot;/WEB- 
    INF/views/flows&quot;)
				.addFlowLocationPattern(&quot;/**/*-flow.xml&quot;).build();
	}

	@Bean
	public FlowBuilderServices flowBuilderServices() {
		return   
       
    getFlowBuilderServicesBuilder().
    setViewFactoryCreator(mvcViewFactoryCreator())
     .setValidator(validator()).setDevelopmentMode(true).build();
	}

	@Bean
  	public MvcViewFactoryCreator mvcViewFactoryCreator() {
		MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator();
		factoryCreator.setViewResolvers(Collections.singletonList
        (this.AppConfig.viewResolver()));
		factoryCreator.setUseSpringBeanBinding(true);
		return factoryCreator;
	}

	@Bean
	public LocalValidatorFactoryBean validator() {
		return new LocalValidatorFactoryBean();
	}

      }

**web.xml**

    &lt;web-app xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/javaee 
		 http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd&quot;
	version=&quot;3.1&quot;&gt;
	&lt;display-name&gt;Archetype Created Web Application&lt;/display-name&gt;

 	&lt;servlet&gt;
		&lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
		&lt;servlet- 
        class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;

 		&lt;init-param&gt;
			&lt;param-name&gt;throwExceptionIfNoHandlerFound&lt;/param-name&gt;
			&lt;param-value&gt;true&lt;/param-value&gt;
		&lt;/init-param&gt;

		&lt;multipart-config&gt;
			&lt;max-file-size&gt;2097152&lt;/max-file-size&gt;
			&lt;max-request-size&gt;4194304&lt;/max-request-size&gt;
			&lt;file-size-threshold&gt;1048576&lt;/file-size-threshold&gt;
		&lt;/multipart-config&gt;
	&lt;/servlet&gt;

	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
 
	
	&lt;context-param&gt;
		&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
		&lt;param-value&gt;
			/WEB-INF/spring-security.xml
		&lt;/param-value&gt;
	&lt;/context-param&gt;
	
	&lt;filter&gt;
		&lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
		&lt;filter- 
    class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
	&lt;/filter&gt;

	&lt;filter-mapping&gt;
		&lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
		&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
	&lt;/filter-mapping&gt;

    &lt;/web-app&gt;  

**dispatcher.xml**

    
    &lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
	xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
	xmlns:mvc=&quot;http://www.springframework.org/schema/mvc&quot;
	xmlns:wf=&quot;http://www.springframework.org/schema/webflow-config&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;
	
	http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/webflow-config
    http://www.springframework.org/schema/webflow-config/spring-webflow- 
    config.xsd&quot;&gt;

	&lt;context:component-scan
		base-package=&quot;com.springboot.wabit&quot; /&gt;

	&lt;bean id=&quot;viewResolver&quot;
		 
    class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;&gt;

		&lt;property name=&quot;prefix&quot; value=&quot;/WEB-INF/views/&quot; /&gt;
		&lt;property name=&quot;suffix&quot; value=&quot;.jsp&quot; /&gt;
	&lt;/bean&gt;

 	&lt;bean id=&quot;multipartResolver&quot;
		  class=&quot;org.springframework.web.multipart.
    support.StandardServletMultipartResolver&quot; /&gt;

 	&lt;mvc:annotation-driven /&gt;
	&lt;mvc:resources location=&quot;/assets/&quot;
		mapping=&quot;/resources/**&quot; /&gt;

 	&lt;wf:flow-executor id=&quot;flowExecutor&quot;
		flow-registry=&quot;flowRegistry&quot; /&gt;

	&lt;wf:flow-registry id=&quot;flowRegistry&quot;
		base-path=&quot;/WEB-INF/views/flows&quot;
		flow-builder-services=&quot;flowBuilderServices&quot;&gt;
		&lt;wf:flow-location-pattern
			value=&quot;/**/*-flow.xml&quot; /&gt;
	&lt;/wf:flow-registry&gt;

	&lt;wf:flow-builder-services
		id=&quot;flowBuilderServices&quot; view-factory-creator=&quot;viewFactoryCreator&quot;
		validator=&quot;validator&quot; /&gt;

	&lt;bean
		class=&quot;org.springframework.webflow.mvc.servlet.FlowHandlerAdapter&quot;&gt;
		&lt;property name=&quot;flowExecutor&quot; ref=&quot;flowExecutor&quot; /&gt;
	&lt;/bean&gt;

	&lt;bean
		class=&quot;org.springframework.webflow.mvc.servlet.FlowHandlerMapping&quot;&gt;
		&lt;property name=&quot;flowRegistry&quot; ref=&quot;flowRegistry&quot; /&gt;
		&lt;property name=&quot;order&quot; value=&quot;-1&quot; /&gt;
	&lt;/bean&gt;

	&lt;bean id=&quot;viewFactoryCreator&quot;
		class=&quot;org.springframework.webflow.mvc.builder.MvcViewFactoryCreator&quot;&gt;
		&lt;property name=&quot;viewResolvers&quot; ref=&quot;viewResolver&quot; /&gt;
	&lt;/bean&gt;

	 	&lt;bean id=&quot;validator&quot;
		class=&quot;org.springframework.validation.
       beanvalidation.LocalValidatorFactoryBean&quot; /&gt;
       &lt;/beans&gt;

**pom.xml**

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
    &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
	xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 
     http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
	  
       &lt;modelVersion&gt; 4.0.0 &lt;/modelVersion&gt;
	   &lt;groupId&gt; com.springboot &lt;/groupId&gt;
	   &lt;artifactId&gt; wabit &lt;/artifactId&gt;
	   &lt;version&gt; 0.0.1-SNAPSHOT &lt;/version&gt;
	   &lt;packaging&gt; war &lt;/packaging&gt;

	&lt;name&gt;wabit&lt;/name&gt;
	&lt;description&gt;Demo project for Spring Boot&lt;/description&gt;

	&lt;parent&gt;
		&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
		&lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
		&lt;version&gt;2.0.6.RELEASE&lt;/version&gt;
		&lt;relativePath /&gt; &lt;!-- lookup parent from repository --&gt;
	&lt;/parent&gt;

	&lt;properties&gt;
		&lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
		&lt;project.reporting.outputEncoding&gt;UTF- 
    8&lt;/project.reporting.outputEncoding&gt;
		&lt;java.version&gt;1.8&lt;/java.version&gt;
	&lt;/properties&gt;

	&lt;dependencies&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-actuator&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-data-rest&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-starter-web-services&lt;/artifactId&gt;
		&lt;/dependency&gt;

		 &lt;dependency&gt;
			&lt;groupId&gt;org.springframework.webflow&lt;/groupId&gt;
			&lt;artifactId&gt;spring-webflow&lt;/artifactId&gt;
			&lt;version&gt;2.5.0.RELEASE&lt;/version&gt;
		&lt;/dependency&gt;

		&lt;dependency&gt;
			&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
			&lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;
			&lt;scope&gt;runtime&lt;/scope&gt;
		&lt;/dependency&gt;
  
 		&lt;dependency&gt;
			&lt;groupId&gt;mysql&lt;/groupId&gt;
			&lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
			&lt;version&gt;8.0.13&lt;/version&gt;
		&lt;/dependency&gt;

  		&lt;dependency&gt;
			&lt;groupId&gt;javax.servlet&lt;/groupId&gt;
			&lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
			&lt;version&gt;3.1.0&lt;/version&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;

		&lt;!-- database connection pooling --&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
			&lt;artifactId&gt;commons-dbcp2&lt;/artifactId&gt;
			&lt;version&gt;2.1.1&lt;/version&gt;
			&lt;exclusions&gt;
				&lt;exclusion&gt;
					&lt;groupId&gt;commons-logging&lt;/groupId&gt;
					&lt;artifactId&gt;commons-logging&lt;/artifactId&gt;
				&lt;/exclusion&gt;
			&lt;/exclusions&gt;
		&lt;/dependency&gt;
 
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.tomcat.embed&lt;/groupId&gt;
			&lt;artifactId&gt;tomcat-embed-jasper&lt;/artifactId&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;
 
 		&lt;dependency&gt;
			&lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
			&lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
			&lt;version&gt;2.3.1&lt;/version&gt;
		&lt;/dependency&gt;
 
  		&lt;dependency&gt;
			&lt;groupId&gt;org.javassist&lt;/groupId&gt;
			&lt;artifactId&gt;javassist&lt;/artifactId&gt;
			&lt;version&gt;3.27.0-GA&lt;/version&gt;
		&lt;/dependency&gt;


		&lt;dependency&gt;
			&lt;groupId&gt;commons-digester&lt;/groupId&gt;
			&lt;artifactId&gt;commons-digester&lt;/artifactId&gt;
			&lt;version&gt;2.1&lt;/version&gt;
		&lt;/dependency&gt;

 		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
			&lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
			&lt;version&gt;3.1.1&lt;/version&gt;
		&lt;/dependency&gt;
  	&lt;/dependencies&gt;
	
      &lt;build&gt;
		&lt;finalName&gt;wabSpring&lt;/finalName&gt;
		&lt;plugins&gt;
			&lt;plugin&gt;
				&lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
				&lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
			&lt;/plugin&gt;
		&lt;/plugins&gt;
	&lt;/build&gt;

       &lt;/project&gt;


   
  
**Log**

     *Oct-2020 11:26:03.558 SEVERE [http-nio-8080-exec-52] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: 
	org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/wabSpring]]
		at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
		at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
		at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:743)
		at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:719)
		at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
		at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:970)
		at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
		at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1634)
		at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
		at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
		at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
		at java.lang.reflect.Method.invoke(Unknown Source)
		at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:286)
		at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown Source)
		at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
		at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1565)
		at org.apache.catalina.manager.HTMLManagerServlet.upload(HTMLManagerServlet.java:289)
		at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:207)
		at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
		at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
		at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
		at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
		at org.apache.catalina.filters.CsrfPreventionFilter.doFilter(CsrfPreventionFilter.java:211)
		at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
		at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
		at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
		at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
		at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
		at org.apache.catalina.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:109)
		at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
		at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
		at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
		at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
		at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:668)
		at org.apache.catalina.valves.RequestFilterValve.process(RequestFilterValve.java:348)
		at org.apache.catalina.valves.RemoteAddrValve.invoke(RemoteAddrValve.java:52)
		at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
		at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
		at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:690)
		at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
		at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
		at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:616)
		at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
		at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818)
		at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1626)
		at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
		at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
		at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
		at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
		at java.lang.Thread.run(Unknown Source)
	Caused by: java.lang.NullPointerException
		at com.springboot.wabit.config.WebAppInitializer.onStartup(WebAppInitializer.java:26)
		at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
		at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5144)
		at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
		... 48 more*    


Is there anything I need to change in WebAppInitializer file? My apllication start on tomcat if I do not include dispatcher-servlet.xml file, but I dont think thats good way to start the app.

</details>


# 答案1
**得分**: 1

```java
@Configuration
public class AppConfig implements WebMvcConfigurer {

    private final WebFlowConfig webFlowConfig;

    public AppConfig(WebFlowConfig webFlowConfig) {
      this.webFlowConfig = webFlowConfig;
    }

    public void addViewControllers(ViewControllerRegistry registry) {
      registry.addViewController("/").setViewName("index");
    }
    
    @Bean
    public FlowHandlerAdapter flowHandlerAdapter() {
        FlowHandlerAdapter handlerAdapter = new FlowHandlerAdapter();
        handlerAdapter.setFlowExecutor(this.webFlowConfig.flowExecutor());
        handlerAdapter.setSaveOutputToFlashScopeOnRedirect(true);
        return handlerAdapter;
    }
    
    @Bean
    public FlowHandlerMapping flowHandlerMapping() {
        FlowHandlerMapping handlerMapping = new FlowHandlerMapping();
        handlerMapping.setOrder(-1);
        handlerMapping.setFlowRegistry(this.webFlowConfig.flowRegistry());
        return handlerMapping;
    }
}
@Configuration
public class WebFlowConfig extends AbstractFlowConfiguration {

    @Bean
    public FlowExecutor flowExecutor() {
        return getFlowExecutorBuilder(flowRegistry())
            .addFlowExecutionListener(new SecurityFlowExecutionListener(), "*")
            .build();
    }
    
    @Bean
    public FlowDefinitionRegistry flowRegistry() {
        return getFlowDefinitionRegistryBuilder()
            .setBasePath("/WEB-INF/views/flows")
            .addFlowLocationPattern("/**/*-flow.xml")
            .build();
    }
    
    @Bean
    public FlowBuilderServices flowBuilderServices(MvcViewFactoryCreator viewFactoryCreator, Validator validator) {
        return getFlowBuilderServicesBuilder()
            .setViewFactoryCreator(viewFactoryCreator)
            .setValidator(validator)
            .setDevelopmentMode(true)
            .build();
    }
    
    @Bean
    public MvcViewFactoryCreator mvcViewFactoryCreator(List<ViewResolver> viewResolvers) {
        MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator();
        factoryCreator.setViewResolvers(viewResolvers);
        factoryCreator.setUseSpringBeanBinding(true);
        return factoryCreator;
    }
}
@SpringBootApplication
public class YourApplication extends SpringBootServletInitializer {

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(YourApplication.class);
    }
}
spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsps
spring.servlet.multipart.maxFileSize=2MB

Please note that I've provided the translated Java code, along with the properties content. If you have any questions or need further assistance, feel free to ask.

英文:
  1. Delete your web.xml
  2. Delete your WebAppInitializer
  3. Delete your dispatcher.xml
  4. Remove @CompoentScan from your WebFlowConfig
  5. Cleanup your AppConfig (only leave the WebFlow configuration stuff)
  6. Put properties in your application.properties
  7. Let your @SpringBootApplication extend SpringBootServletInitializer
  8. Build and deploy.

Your AppConfig does too much and disables Spring Boot auto-config only leave the WebFlow configuration.

@Configuration
public class AppConfig implements WebMvcConfigurer {

    private final WebFlowConfig webFlowConfig;

    public AppConfig(WebFlowConfig webFlowConfig) {
      this.webFlowConfig=webFlowConfig;
    }

    public void addViewControllers(ViewControllerRegistry registry) {
      registry.addViewController(&quot;/&quot;).setViewName(&quot;index&quot;);
    }
    
    @Bean
    public FlowHandlerAdapter flowHandlerAdapter() {
        FlowHandlerAdapter handlerAdapter = new FlowHandlerAdapter();
        handlerAdapter.setFlowExecutor(this.webFlowConfig.flowExecutor());
        handlerAdapter.setSaveOutputToFlashScopeOnRedirect(true);
        return handlerAdapter;
    }
    
    @Bean
    public FlowHandlerMapping flowHandlerMapping() {
        FlowHandlerMapping handlerMapping = new FlowHandlerMapping();
        handlerMapping.setOrder(-1);
        handlerMapping.setFlowRegistry(this.webFlowConfig.flowRegistry());
        return handlerMapping;
    }
}

Your `

@Configuration
public class WebFlowConfig extends AbstractFlowConfiguration {

    @Bean
    public FlowExecutor flowExecutor() {
        return 
    getFlowExecutorBuilder(flowRegistry()).addFlowExecutionListener(new 
       SecurityFlowExecutionListener(), &quot;*&quot;)
                .build();
    }
    
    @Bean
    public FlowDefinitionRegistry flowRegistry() {
        return getFlowDefinitionRegistryBuilder().setBasePath(&quot;/WEB- 
    INF/views/flows&quot;)
                .addFlowLocationPattern(&quot;/**/*-flow.xml&quot;).build();
    }
    
    @Bean
    public FlowBuilderServices flowBuilderServices(MvcViewFactoryCreator viewFactoryCreator, Validator validator) {
        return   
       
    getFlowBuilderServicesBuilder().
    setViewFactoryCreator(viewFactoryCreator)
     .setValidator(validator).setDevelopmentMode(true).build();
    }
    
    @Bean
    public MvcViewFactoryCreator mvcViewFactoryCreator(List&lt;ViewResolver&gt; viewResolvers) {
        MvcViewFactoryCreator factoryCreator = new MvcViewFactoryCreator();
        factoryCreator.setViewResolvers(viewResolvers);
        factoryCreator.setUseSpringBeanBinding(true);
        return factoryCreator;
    }

  }

You already should have an @SpringBootApplication annotated class, if you don't create it and place it in com.springboot.wabit (as I assume that is your top-level package) and have it extend SpringBootServletInitializer. As explained as well in the official documentation.

@SpringBootApplication
public class YourApplication extends SpringBootServletInitializer {

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

  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
	return builder.sources(YourApplication.class);
  }
}

Now as you removed some beans from the AppConfig class you will need to add some properties to the application.properties to achieve the same.

spring.mvc.view.prefix=/WEB-INF/views/
spring.mvc.view.suffix=.jsps
spring.servlet.multipart.maxFileSize=2MB

Finally your dependencies are a bit of a mess you don't need the servlet-api, javaassist and maven-shade dependencies. Either you don't need them or they are already included in the spring-boot-starter-* projects you import.

huangapple
  • 本文由 发表于 2020年10月8日 13:35:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/64256379.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定