java.io.FileNotFoundException:无法打开ServletContext资源Spring Boot

时间:2017-12-13 14:39:35

标签: java spring-boot websphere websphere-liberty

我正在使用一个应用程序,使用Spring Boot + Spring Legacy(能够在运行WebSphere的旧服务器中部署代码)。 我在WebSphere Liberty中做了一些测试,运行得很好。但是,当我在WebSphere Application Server上部署它时,我得到了这个错误:

     [12/13/17 7:56:47:170 MST] 00000012 SystemOut     O 07:56:47.169 [server.startup : 2] ERROR org.springframework.web.servlet.DispatcherServlet - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from ServletContext resource [/com.org.entitymigration.EntityMigrationApplication]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/com.org.entitymigration.EntityMigrationApplication]
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:168)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:124)
        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:140)
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:116)
        at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:84)
        at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:87)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:267)
        at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
        at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:230)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:156)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:48)
        at com.ibm.ws.webcontainer.webapp.WebApp.notifyServletContextCreated(WebApp.java:1721)
        at com.ibm.ws.webcontainer.webapp.WebApp.commonInitializationFinish(WebApp.java:388)
        at com.ibm.ws.webcontainer.webapp.WebAppImpl.initialize(WebAppImpl.java:299)
        at com.ibm.ws.webcontainer.webapp.WebGroupImpl.addWebApplication(WebGroupImpl.java:100)
        at com.ibm.ws.webcontainer.VirtualHostImpl.addWebApplication(VirtualHostImpl.java:166)
        at com.ibm.ws.webcontainer.WSWebContainer.addWebApp(WSWebContainer.java:732)
        at com.ibm.ws.webcontainer.WSWebContainer.addWebApplication(WSWebContainer.java:617)
        at com.ibm.ws.webcontainer.component.WebContainerImpl.install(WebContainerImpl.java:376)
        at com.ibm.ws.webcontainer.component.WebContainerImpl.start(WebContainerImpl.java:668)
        at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:1146)
        at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:1320)
        at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:611)
        at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:945)
        at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:759)
        at com.ibm.ws.runtime.component.ApplicationMgrImpl$3.run(ApplicationMgrImpl.java:2082)
        at com.ibm.ws.security.auth.ContextManagerImpl.runAs(ContextManagerImpl.java:5397)
        at com.ibm.ws.security.auth.ContextManagerImpl.runAsSystem(ContextManagerImpl.java:5485)
        at com.ibm.ws.security.core.SecurityContext.runAsSystem(SecurityContext.java:255)
        at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:2087)
        at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:434)
        at com.ibm.ws.runtime.component.CompositionUnitImpl.start(CompositionUnitImpl.java:123)
        at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.start(CompositionUnitMgrImpl.java:377)
        at com.ibm.ws.runtime.component.CompositionUnitMgrImpl.access$300(CompositionUnitMgrImpl.java:123)
        at com.ibm.ws.runtime.component.CompositionUnitMgrImpl$CUInitializer.run(CompositionUnitMgrImpl.java:944)
        at com.ibm.wsspi.runtime.component.WsComponentImpl$_AsynchInitializer.run(WsComponentImpl.java:496)
        at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1662)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/com.ibm.entitymigration.EntityMigrationApplication]
        at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:99)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:152)

我将ContextLoader指向具有注释@SpringBootApplication的Java类。这些是我的文件:

的build.gradle

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

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

sourceCompatibility = 1.6
targetCompatibility = 1.6

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

project.webAppDirName = 'WebContent'

mainClassName = 'com.org.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.springframework', name: 'spring-context', version: '4.3.13.RELEASE'

    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'
}

的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.org.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>

EntityMigrationApplication.java(SpringBootApplication)

package com.org.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);
    }
}

配置类

package com.org.entitymigration.conf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;

import com.org.entitymigration.models.LoginInputParamFilter;
import com.org.entitymigration.services.EntityAuthenticationFailureHandler;
import com.org.entitymigration.services.EntityAuthenticationProvider;

@Configuration
@EnableWebSecurity
@ComponentScan
public class WebSecurityConfig extends WebSecurityConfigurerAdapter   {

     @Autowired
      private EntityAuthenticationProvider authenticationProvider;

     @Bean
     public LoginInputParamFilter loginInputParamFilter()
                throws Exception {
         LoginInputParamFilter loginInputParamFilter = new LoginInputParamFilter();
         loginInputParamFilter.setAuthenticationManager(authenticationManagerBean());
            return loginInputParamFilter;
     }

     protected void configure(
        AuthenticationManagerBuilder auth) throws Exception {

          auth.authenticationProvider(authenticationProvider);
      }

      protected void configure(HttpSecurity http) throws Exception {
          http.formLogin()
            .loginPage("/login")
            .permitAll()
            .failureHandler(new EntityAuthenticationFailureHandler())
            .and()
            .logout()
            .permitAll();

        http.authorizeRequests()
            .antMatchers("/css/**", "/img/**", "/js/**")
            .permitAll()
            .anyRequest()
            .authenticated();


        http.authorizeRequests()
          .antMatchers("/resources/**","/rest/**","/login*", "/css/**", "/img/**", "/js/**","/error").permitAll()
          .anyRequest().authenticated()
          .and()
          .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout")).logoutSuccessUrl("/login");

          http
          .addFilterBefore(loginInputParamFilter(), LoginInputParamFilter.class);
      }


       @Autowired
      public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
          auth.authenticationProvider(authenticationProvider);

      }


}

WebSphere Application Server缺少什么?

谢谢。

0 个答案:

没有答案