Java 如何将SpringBoot与Servlet3.0容器集成,并使其在WebSphere8.5.5服务器中工作?
我有一个使用SpringBoot开发的工作项目,SpringBoot安全性和SpringDataREST使用Maven 作为一个独立的班级工作很好。在Tomcat的战争部署也很好。我已经在与Maven的战争中生成了一个EAR,并部署在WAS8.5.5中,但它不起作用 独立Java类,它与嵌入式Tomcat以及外部Tomcat7配合得很好。同样的失败是从websphere开始的,我不确定是否缺少任何其他配置Java 如何将SpringBoot与Servlet3.0容器集成,并使其在WebSphere8.5.5服务器中工作?,java,websphere-8,spring-boot-maven-plugin,Java,Websphere 8,Spring Boot Maven Plugin,我有一个使用SpringBoot开发的工作项目,SpringBoot安全性和SpringDataREST使用Maven 作为一个独立的班级工作很好。在Tomcat的战争部署也很好。我已经在与Maven的战争中生成了一个EAR,并部署在WAS8.5.5中,但它不起作用 独立Java类,它与嵌入式Tomcat以及外部Tomcat7配合得很好。同样的失败是从websphere开始的,我不确定是否缺少任何其他配置 package com.marsh.forms; import org.spri
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;
}
}
我注意到两个问题:
[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.
[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
我已经为“@ControllerAdvice(basePackageClasses=RepositoryRestExceptionHandler.class)”使用了最新的spring启动版本类是必需的。解决方案:我可以使用servlet2.5容器解决此问题,这意味着我已经像下面那样更改了web.xml,并按照下面的线程步骤使其工作,因为我无法获得快速解决方案,使其在WAS 5.5.5.0中与Servlet3.0一起工作 web.xml
<?xml version="1.0" encoding="UTF-8"?>
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd“>
上下文配置位置
com.marsh.forms.FormsRestation2
org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener
Web应用程序创建的原型
春天
org.springframework.web.servlet.DispatcherServlet
上下文属性
org.springframework.web.context.WebApplicationContext.ROOT
1.
春天
/*
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
错误
要求
由于更改了容器版本,我还降低了hibernate和spring boot 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
战争
org.springframework.boot
SpringBootStarterWeb
org.springframework.boot
弹簧启动机tomcat
javax.validation
验证api
org.springframework.boot
弹簧靴遗产
1.0.1.1发布
org.springframework.boot
spring引导启动器数据jpa
org.hibernate.javax.persistence
hibernate-jpa-2.1-api
org.springframework.boot
弹簧启动启动器数据rest
org.springframework.boot
弹簧启动机tomcat
假如
org.springframework.boot
弹簧启动安全
org.hibernate
冬眠核心
4.1.12.最终版本
org.hibernate
休眠实体管理器
4.1.12.最终版本
org.hibernate.javax.persistence
hibernate-jpa-2.0-api
1.0.1.最终版本
com.oracle
ojdbc6
11.2.0.4.0
javax.servlet
javax.servlet-api
3.0.1
org.springframework.boot
弹簧起动试验
测试
com.marsh.forms.FormsRestation2
UTF-8
UTF-8
1.7
org.springframework.boot
springbootmaven插件
org.apache.maven.plugins
maven战争插件
spring-boot-starter-data-rest-1.3.0.M5.jar,hibernate-core-4.3.11.Final.jar
org.springframework.data.rest.core,org.hibernate,javax.persistence
testwar1
abc
弹簧启动机等级:
@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;
}
}
@配置
@EnableWebMvc
@组件扫描
@启用自动配置
@EnableConfigurationProperties
公共类FormsRestation2{
公共静态void main(字符串[]args)引发异常{
ApplicationContext ctx=SpringApplication.run(
FormsRestationApplication2.class,args);
}
私有静态类applicationClass=FormsRestationApplication2.Class;
@豆子
公共DispatcherServlet DispatcherServlet(){
DispatcherServlet ds=新DispatcherServlet();
ds.SetThroweExceptionIfNoHandlerFound(真);
返回ds;
}
}
[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
<?xml version="1.0" encoding="UTF-8"?>
<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>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>ERROR</dispatcher>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>
<?xml version="1.0"?>
<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>
@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;
}
}