Spring Legacy启动两次,错误没有找到WebApplicationContext

时间:2017-12-11 13:14:59

标签: java spring spring-boot

我目前正在为应用程序使用Spring Boot,但我需要使用WebSphere Application Server将它部署在旧服务器中。 我开始按照步骤here进行操作 使用 Spring Legacy 。但是,我遇到了一些麻烦: 1.春天开始两次 2.我在第二次启动时在控制台上收到此错误:

    2017-12-11 11:04:36.135  INFO 9304 --- [ecutor-thread-4] com.ibm.ws.webcontainer.webapp           : SRVE0292I: Servlet Message - [EntityMigration]:.Initializing Spring FrameworkServlet 'appServletDispatcher'
2017-12-11 11:04:36.135  INFO 9304 --- [ecutor-thread-4] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'appServletDispatcher': initialization started
2017-12-11 11:04:36.137 ERROR 9304 --- [ecutor-thread-4] o.s.web.servlet.DispatcherServlet        : Context initialization failed

java.lang.IllegalStateException: No WebApplicationContext found: initializer not registered?
    at org.springframework.web.servlet.FrameworkServlet.findWebApplicationContext(FrameworkServlet.java:594) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:549) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494) ~[spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:171) [spring-webmvc-4.3.13.RELEASE.jar:4.3.13.RELEASE]
    at javax.servlet.GenericServlet.init(GenericServlet.java:244) [com.ibm.websphere.javaee.servlet.3.1_1.0.18.jar:na]
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.init(ServletWrapper.java:297) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.loadOnStartupCheck(ServletWrapper.java:1393) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at com.ibm.ws.webcontainer.webapp.WebApp.doLoadOnStartupActions(WebApp.java:1153) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinally(WebApp.java:1121) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:1022) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at com.ibm.ws.webcontainer.webapp.WebApp.initialize(WebApp.java:6550) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApp(DynamicVirtualHost.java:469) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost.startWebApplication(DynamicVirtualHost.java:464) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at com.ibm.ws.webcontainer.osgi.WebContainer.startWebApplication(WebContainer.java:1119) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at com.ibm.ws.webcontainer.osgi.WebContainer.access$000(WebContainer.java:103) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at com.ibm.ws.webcontainer.osgi.WebContainer$2.run(WebContainer.java:931) [com.ibm.ws.webcontainer_1.1.18.jar:na]
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [na:1.8.0_151]
    at java.util.concurrent.FutureTask.run(Unknown Source) [na:1.8.0_151]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_151]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_151]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_151]

2017-12-11 11:04:36.259 ERROR 9304 --- [ecutor-thread-4] com.ibm.ws.webcontainer.servlet          : SRVE0271E: Uncaught init() exception created by servlet [appServletDispatcher] in application [EntityMigration]: java.lang.IllegalStateException: No WebApplicationContext found: initializer not registered?
2017-12-11 11:04:36.262 ERROR 9304 --- [ecutor-thread-4] com.ibm.ws.webcontainer.webapp           : SRVE0276E: Error while initializing Servlet [appServletDispatcher]: javax.servlet.ServletException: SRVE0207E: Uncaught initialization exception created by servlet

我必须在我的项目中配置web.xml和一些配置:

web.xml(已编辑

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>com.ibm.entitymigration.EntityMigrationApplication</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>metricsFilter</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

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

    <servlet>
        <servlet-name>appServletDispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextAttribute</param-name>
            <param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServletDispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>  

</web-app>

EntityMigrationProject.java(SpringBootApplication)

package com.ibm.entitymigration;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;

@SpringBootApplication
public class EntityMigrationApplication extends SpringBootServletInitializer {

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

的build.gradle

group 'com.ibm.entitymigration'
version '1.0-SNAPSHOT'

apply plugin: 'java-library'
apply plugin: 'eclipse-wtp'
apply plugin: 'application'
apply plugin: 'war'

sourceCompatibility = 1.5
targetCompatibility = 1.5

compileJava {
    options.encoding = 'UTF-8'
    options.fork = true
}

project.webAppDirName = 'WebContent'

mainClassName = 'com.ibm.entitymigration.Application'

sourceSets {
    main {
        java.srcDirs = ['src/main/java']
        resources.srcDirs = ['src/main/resources']
    }
    test.java.srcDirs = ['src/test/java']
}

repositories {
    jcenter()
}

ext {
    spring_version = '1.5.9.RELEASE'
    thymeleaf_version = '3.0.9.RELEASE'
    thymeleaf_layout_version = '2.2.2'
}

configurations {
    providedRuntime
    compile.exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}

dependencies {
    compileOnly group: 'javax.servlet', name: 'servlet-api', version: '2.5'
    compile group: 'org.springframework.boot', name: 'spring-boot-legacy', version: '1.1.0.RELEASE'

    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: spring_version
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: spring_version
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: spring_version
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-security' , version: spring_version

    compile group: 'org.thymeleaf', name: 'thymeleaf', version: thymeleaf_version
    compile group: 'org.thymeleaf', name: 'thymeleaf-spring4', version: thymeleaf_version
    compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: thymeleaf_layout_version

    compile group: 'com.jcraft', name:'jsch', version:'0.1.52'

    testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: spring_version
}

war {
    baseName = 'EntityMigration'
}

eclipse {
    wtp.facet {
        facets = []
        facet name: 'jst.java', version: '1.5'
        facet name: 'jst.web', version: '2.5'
    }
}

我做错了什么?

修改 要解决此问题,您只需将contextAtribute更改为web.xml上的 org.springframework.web.context.WebApplicationContext.ROOT

0 个答案:

没有答案