简体   繁体   English

如何将Spring Boot与Servlet 3.0容器集成在一起并使其在Websphere 8.5.5服务器中工作?

[英]How to integrate Spring boot with servlet 3.0 container and make it work in Websphere 8.5.5 server?

I have a working project developed with Spring boot, spring boot security and spring data rest with Maven. 我有一个使用Spring Boot,Spring Boot安全性和Maven开发的Spring Data Rest开发的工作项目。

As a standalone class working fine. 作为一个独立的类工作正常。 WAR deployment in Tomcat also working fine. Tomcat中的WAR部署也可以正常工作。 I have generated an EAR out of the WAR with Maven and deployed in WAS 8.5.5 is not working. 我已经使用Maven从WAR中生成了一个EAR,并在WAS 8.5.5中部署了它无法正常工作。

Standalone Java class which is woking fine with embedded Tomcat also with external Tomcat 7. Same failing to start with websphere not sure is any other configuration I am missing? 独立的Java类可以与嵌入式Tomcat以及外部Tomcat 7一起使用。同样,如果无法从websphere开始,还不确定是否缺少其他配置吗?

    package com.marsh.forms;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Configuration
@EnableWebMvc
@ComponentScan
@EnableAutoConfiguration
@EnableConfigurationProperties
public class FormsRestApplication2 extends SpringBootServletInitializer {


    public static void main(String[] args) throws Exception {
        ApplicationContext ctx = SpringApplication.run(
                FormsRestApplication2.class, args);

    }   

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }

    private static Class<FormsRestApplication2> applicationClass = FormsRestApplication2.class;

    @Bean
    // Magic entry
    public DispatcherServlet dispatcherServlet() {
        DispatcherServlet ds = new DispatcherServlet();
        ds.setThrowExceptionIfNoHandlerFound(true);
        return ds;
    }

}

WAR pom.xml 战争pom.xml

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.marsh</groupId>
        <artifactId>testparent1</artifactId>
        <version>0.1</version>
    </parent>
    <groupId>com.marsh</groupId>
    <artifactId>testwar1</artifactId>
    <version>0.1</version>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>tomcat-embed-el</artifactId>
                    <groupId>org.apache.tomcat.embed</groupId>
                </exclusion>
                    <exclusion><groupId>javax.validation</groupId>
                    <artifactId>validation-api</artifactId></exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>

        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        **<!-- <dependency> 
            <groupId>org.springframework.boot</groupId> 
            <artifactId>spring-boot-starter-tomcat</artifactId> 
            <scope>provided</scope> 
        </dependency> -->**

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc6</artifactId>
            <version>11.2.0.4.0</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <properties>
        <start-class>com.marsh.forms.FormsRestApplication2</start-class>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.7</java.version>        
    </properties>
    <build>
        <plugins>
                            <plugin>
                     <groupId>org.apache.maven.plugins</groupId>
                     <artifactId>maven-war-plugin</artifactId>
                        <configuration>
                            <archive>
                            <manifestEntries>
                                <Ignore-Scanning-Archives>spring-boot-starter-data-rest-1.3.0.M5.jar, hibernate-core-4.3.11.Final.jar</Ignore-Scanning-Archives>  
                                <Ignore-Scanning-Packages>org.springframework.data.rest.core, org.hibernate,javax.persistence </Ignore-Scanning-Packages>
                            </manifestEntries>
                            </archive>
                        </configuration>
                </plugin>

        </plugins>
        <finalName>testwar1</finalName>
    </build>
    <organization>
        <name>marsh</name>
        <url>www.marsh.com</url>
    </organization>
    <scm>
        <developerConnection>szdasd</developerConnection>
    </scm>
</project>

ear pom.xml 耳朵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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.marsh</groupId>
    <artifactId>testparent1</artifactId>
    <version>0.1</version>
  </parent>
  <artifactId>testear1</artifactId>
  <packaging>ear</packaging>
<dependencies>
        <dependency>
            <groupId>com.marsh</groupId>
            <artifactId>testwar1</artifactId>
            <version>0.1</version>
            <type>war</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.10.1</version>
                <configuration>
                    <skinnyWars>true</skinnyWars>
                    <defaultJavaBundleDir>lib</defaultJavaBundleDir>
                    <modules>
                        <webModule>
                            <groupId>com.marsh</groupId>
                            <artifactId>testwar1</artifactId>
                            <contextRoot>/forms</contextRoot>
                        </webModule>

                    </modules>
                    <generateApplicationXml>true</generateApplicationXml>
                </configuration>
            </plugin>

        </plugins>
        <finalName>forms</finalName>

    </build>
</project>

parent pom.xml 父pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.marsh</groupId>
    <artifactId>testparent1</artifactId>
    <version>0.1</version>
    <packaging>pom</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <!-- <version>1.2.7.RELEASE</version> -->
        <version>1.3.0.M5</version>
        <relativePath>/</relativePath>
    </parent>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
                <version>1.3.0.M5</version>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <modules>
        <!-- <module>testwar</module> <module>testear</module> -->
        <module>testwar1</module>
        <module>testear1</module>
    </modules>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
                <!-- <version>3.1</version> -->
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>

Ear generated successful and I can see proper update in application.xml about was project with context root. Ear生成成功,我可以在application.xml中看到有关带有上下文根目录的项目的正确更新。 War also generated fine with classes and lib metaInf info. 使用类和lib metaInf信息也可以很好地产生战争。

Manifest-Version: 1.0
Implementation-Vendor: xxx
Implementation-Title: testwar1
Implementation-Version: 0.1
Implementation-Vendor-Id: com.marsh
Ignore-Scanning-Packages: org.springframework.data.rest.core, org.hibe
 rnate,javax.persistence
Built-By: abc
Build-Jdk: 1.7.0_80
Ignore-Scanning-Archives: spring-boot-starter-data-rest-1.3.0.M5.jar, 
 hibernate-core-4.3.11.Final.jar
Created-By: Apache Maven 3.0.4
Archiver-Version: Plexus Archiver

Couple of issues I noticed: 我注意到的几个问题:

  1. the issue is EAR deploying in server but not WAR and I don't see either spring boot starter or my classes getting loaded or publishing my spring rest data URLs: 问题是EAR部署在服务器中,而不是WAR,并且我没有看到spring boot starter或我的类被加载或发布了spring rest数据URL:

     [11/5/15 18:24:46:088 EST] 00000070 ApplicationMg A WSVR0200I: Starting application: testear1 [11/5/15 18:24:46:088 EST] 00000070 ApplicationMg A WSVR0204I: Application: testear1 Application build level: Unknown [11/5/15 18:24:48:260 EST] 00000070 webapp I com.ibm.ws.webcontainer.webapp.WebGroupImpl WebGroup SRVE0169I: Loading Web Module: Archetype Created Web Application. [11/5/15 18:24:48:397 EST] 00000070 WASSessionCor I SessionContextRegistry getSessionContext SESN0176I: Will create a new session context for application key default_host/forms [11/5/15 18:25:20:583 EST] 00000070 webapp I com.ibm.ws.webcontainer.webapp.WebApp log SRVE0292I: Servlet Message - [testear1#testwar1-0.1.war]:.No Spring WebApplicationInitializer types detected on classpath [11/5/15 18:25:20:583 EST] 00000070 webcontainer I com.ibm.ws.webcontainer.VirtualHostImpl addWebApplication SRVE0250I: Web Module Archetype Created Web Application has been bound to default_host[*:9081,*:80,*:9444,*:5063,*:5062,*:443]. [11/5/15 18:25:20:640 EST] 00000070 ApplicationMg A WSVR0221I: Application started: testear1 [11/5/15 18:25:20:640 EST] 00000070 CompositionUn A WSVR0191I: Composition unit WebSphere:cuname=testear1 in BLA WebSphere:blaname=testear1 started. 
  2. This may be because of version mismatches but i am using jDK7 in all compiler, runtime and WAS 8.5.5 running in JDK7. 这可能是因为版本不匹配,但是我在所有在JDK7中运行的编译器,运行时和WAS 8.5.5中都使用了jDK7。

     [11/5/15 18:23:59:185 EST] 00000072 visitor W com.ibm.ws.amm.scan.util.AnnotationInfoDefaultVisitor visitAnnotation [ com.ibm.ws.amm.scan.util.InfoVisitor@572832628 ] for method [ com.ibm.ws.amm.scan.util.info.impl.MethodInfoImpl@2048932859 ( org.springframework.data.rest.core.annotation.RepositoryRestResource.collectionResourceDescription ) ] Name [ null ] Description [ Lorg/springframework/data/rest/core/annotation/Description; ] Call in violation of protocol [11/5/15 18:23:59:196 EST] 00000072 visitor W com.ibm.ws.amm.scan.util.AnnotationInfoDefaultVisitor visitAnnotation [ com.ibm.ws.amm.scan.util.InfoVisitor@572832628 ] for method [ com.ibm.ws.amm.scan.util.info.impl.MethodInfoImpl@-535225858 ( org.springframework.data.rest.core.annotation.RepositoryRestResource.itemResourceDescription ) ] Name [ null ] Description [ Lorg/springframework/data/rest/core/annotation/Description; ] Call in violation of protocol 

I have used latest spring boot version for "@ControllerAdvice(basePackageClasses = RepositoryRestExceptionHandler.class)" class is required. 我已经为“ @ControllerAdvice(basePackageClasses = RepositoryRestExceptionHandler.class)”类使用了最新的春季启动版本。

Resolution: I could able to resolve this issue with servlet2.5 container meaning i have changed web.xml like below and followed below thread steps to make it work as i could not get quick solution to make it work with servlet 3.0 in WAS 5.5.5.0 解决方案:我可以使用servlet2.5容器解决此问题,这意味着我已经像下面和下面的线程步骤那样更改了web.xml,并按照下面的线程步骤使之工作,因为我无法获得快速的解决方案使其与WAS 5.5中的servlet 3.0一起工作。 5

https://bp3.zendesk.com/hc/en-us/articles/210443048-Running-Spring-Boot-JPA-apps-in-WebSphere-8-5-5 https://bp3.zendesk.com/hc/en-us/articles/210443048-Running-Spring-Boot-JPA-apps-in-WebSphere-8-5-5

web.xml web.xml中

<?xml version="1.0" encoding="UTF-8"?>

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd“>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>com.marsh.forms.FormsRestApplication2</param-value>
</context-param>

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

<display-name>Archetype Created Web Application</display-name>

<servlet>
    <servlet-name>spring</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>spring</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxy

<filter-mapping>
  <filter-name>springSecurityFilterChain</filter-name>
  <url-pattern>/*</url-pattern>
  <dispatcher>ERROR</dispatcher>
  <dispatcher>REQUEST</dispatcher>
</filter-mapping>

since i have changed the container version i have also lowered the hibernate and spring boot jpa version to execute my project. 由于更改了容器版本,因此我还降低了休眠和弹簧启动jpa版本以执行我的项目。

<?xml version="1.0"?>

http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 com.marsh testparent1 0.1 com.marsh testwar1 0.1 war http://maven.apache.org/xsd/maven-4.0.0.xsd“ xmlns =” http://maven.apache.org/POM/4.0.0“ xmlns:xsi =” http:// www。 w3.org/2001/XMLSchema-instance“> 4.0.0 com.marsh testparent1 0.1 com.marsh testwar1 0.1 war

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
            <!-- <exclusion>
                <artifactId>tomcat-embed-el</artifactId>
                <groupId>org.apache.tomcat.embed</groupId>
            </exclusion> -->

                <exclusion>
                <groupId>javax.validation</groupId>
                <artifactId>validation-api</artifactId></exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-legacy</artifactId>
        <version>1.0.1.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.hibernate.javax.persistence</groupId>
                <artifactId>hibernate-jpa-2.1-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-rest</artifactId>
    </dependency>
    <dependency> 
        <groupId>org.springframework.boot</groupId> 
        <artifactId>spring-boot-starter-tomcat</artifactId> 
        <scope>provided</scope> 
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.1.12.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>4.1.12.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.4.0</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>
<properties>
    <start-class>com.marsh.forms.FormsRestApplication2</start-class>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.7</java.version>        
</properties>
<build>
    <plugins>
        <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId> 
            </plugin>
            <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-war-plugin</artifactId>
                    <configuration>
                        <archive>
                        <manifestEntries>
                            <Ignore-Scanning-Archives>spring-boot-starter-data-rest-1.3.0.M5.jar, hibernate-core-4.3.11.Final.jar</Ignore-Scanning-Archives>  
                            <Ignore-Scanning-Packages>org.springframework.data.rest.core, org.hibernate,javax.persistence </Ignore-Scanning-Packages>
                        </manifestEntries>
                        </archive>
                    </configuration>
            </plugin>

    </plugins>
    <finalName>testwar1</finalName>
</build>

<scm>
    <developerConnection>abc</developerConnection>
</scm>

spring boot starter class: 春季启动入门班:

@Configuration
@EnableWebMvc
@ComponentScan
@EnableAutoConfiguration
@EnableConfigurationProperties
public class FormsRestApplication2{ 


    public static void main(String[] args) throws Exception {
        ApplicationContext ctx = SpringApplication.run(
                FormsRestApplication2.class, args);

    }

    private static Class<FormsRestApplication2> applicationClass = FormsRestApplication2.class;

    @Bean   
    public DispatcherServlet dispatcherServlet() {
        DispatcherServlet ds = new DispatcherServlet();
        ds.setThrowExceptionIfNoHandlerFound(true);
        return ds;
    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 websphere 8.5.5 中部署 spring boot web 应用程序 - How to deploy spring boot web application in websphere 8.5.5 IBM Websphere 8.5.5 在 Servlet 3.0 中使用数据源 4.0 版本 - IBM Websphere 8.5.5 use data source 4.0 version in Servlet 3.0 使用Spring Boot和WebSphere 8.5.5进行远程EJB查找 - Remote EJB lookup using Spring Boot and WebSphere 8.5.5 在 Websphere 8.5.5 中部署 spring-boot 2.5.x 应用程序时出错抛出 java.lang.NoClassDefFoundError: javax.servlet.Z80791B3AE7002CB88C246876D9FAA8 - Error deploy spring-boot 2.5.x app in Websphere 8.5.5 throw java.lang.NoClassDefFoundError: javax.servlet.http.HttpSessionIdListener 如何为Servlet 3.0配置Spring Boot 1.2.0并让m2e将Eclipse Facet设置为3.0? - How to configure Spring Boot 1.2.0 for Servlet 3.0 and have m2e set Eclipse Facet to 3.0? 将Spring与WebSphere 8.5.5和Apache Wink一起使用-ClassNotFoundException - Using Spring with WebSphere 8.5.5 and Apache Wink - ClassNotFoundException Websphere 8.5.5上的Spring Data JPA + Hibernate - Spring Data JPA + Hibernate on Websphere 8.5.5 在Websphere应用程序服务器8.5.5上运行liferay portlet - running liferay portlet on websphere application server 8.5.5 WebSphere Application Server 8.5.5上的自定义领域 - Custom Realm on WebSphere Application Server 8.5.5 将Spring与WebSphere 8.5.5和Apache Wink一起使用-服务器启动时出现web.xml错误 - Using Spring with WebSphere 8.5.5 and Apache Wink - web.xml error on server startup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM