在WebSphere 9上运行Spring Boot Application [英] Running Spring Boot Application on WebSphere 9

查看:115
本文介绍了在WebSphere 9上运行Spring Boot Application的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主类为Spring Boot的应用程序:

@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer{

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

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

    private static Class<MyApplication > applicationClass = MyApplication .class;
}

使用gradle.build:

version '1.0'
// dependencies for command line
buildscript {
    ext {
        springBootVersion = '1.4.3.RELEASE'
        dependencyManagementVersion = '0.6.0.RELEASE'
    }
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath "io.spring.gradle:dependency-management-plugin:${dependencyManagementVersion}"
    }
}

apply plugin: "io.spring.dependency-management"
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'idea'

// JDK 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

repositories {
    jcenter()
}

ext {
    springCloudVersion = 'Brixton.SR4'
    springBootVersion = '1.4.3.RELEASE'
    swaggerVersion = '2.4.0'
    jodaTimeVersion = '2.9.4'
    jacksonJodaVersion = '2.5.1'
    junitVersion = '4.12'
    springWsTestVersion = '2.2.3.RELEASE'
    lombokVersion = '1.16.10'
    jsonPathVersion = '2.2.0'
    ehcacheVersion = '3.2.0'
    javaxCacheVersion = '1.0.0'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"
    }
}

sourceSets {
    test {
        java {
            srcDir 'src/test/unit/java'
        }
        resources {
            srcDir 'src/test/unit/resources'
        }
    }
}

tasks.withType(JavaExec) {
    if (System.getProperty("DEBUG", 'false') == 'true') {
        jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006'
    }
}

dependencies {
    // https://mvnrepository.com/artifact/javax/javaee-api
    compile group: 'javax', name: 'javaee-api', version: '7.0'

    /* core libraries */
    compile('org.springframework.cloud:spring-cloud-starter-config') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    compile('org.springframework.boot:spring-boot-starter-web') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    compile("org.springframework.boot:spring-boot-starter-hateoas"){
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    compile 'org.springframework.ws:spring-ws-core'

    // tag::actuator[]; for @RefreshScope
    compile("org.springframework.boot:spring-boot-starter-actuator"){
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    // end::actuator[]
    // logging
    compile('org.springframework.boot:spring-boot-starter-log4j2')
    compile('com.fasterxml.jackson.dataformat:jackson-dataformat-yaml')
    compile('com.fasterxml.jackson.core:jackson-databind')

    // embedded server
    providedRuntime ('org.springframework.boot:spring-boot-starter-tomcat')


    // https://mvnrepository.com/artifact/org.projectlombok/lombok-maven
    compile "org.projectlombok:lombok:${lombokVersion}"

    // https://mvnrepository.com/artifact/com.jayway.jsonpath/json-path
    // A Java DSL for reading JSON documents
    compile "com.jayway.jsonpath:json-path:${jsonPathVersion}"

    //for EhCache
    // https://mvnrepository.com/artifact/org.ehcache/ehcache
    compile "org.ehcache:ehcache:${ehcacheVersion}"
    // https://mvnrepository.com/artifact/javax.cache/cache-api
    compile "javax.cache:cache-api:${javaxCacheVersion}"
    // utilities
    compile "io.springfox:springfox-swagger2:${swaggerVersion}"
    compile "io.springfox:springfox-swagger-ui:${swaggerVersion}"
    compile "joda-time:joda-time:${jodaTimeVersion}"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:${jacksonJodaVersion}"
    compile ("org.springframework.boot:spring-boot-starter-aop") {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    compile "org.aspectj:aspectjweaver:1.8.8"

    /* plugins */

    /* test libraries */
    // unit
    testCompile "junit:junit:${junitVersion}"
    testCompile "org.springframework.boot:spring-boot-starter-test"
    testCompile "org.springframework.ws:spring-ws-test:${springWsTestVersion}"
}

war {
    archiveName = "${project.name}.war"
    manifest {
        attributes 'Main-Class': 'com..content.MyApplication'
    }
}

当我尝试在WebSphere Application Server 9.0传统版上部署war文件时,它会启动,但是需要很长时间.没有war文件,服务器将非常正常地启动和停止,但是在有应用程序的情况下,服务器会挂起.

我想念什么吗?

谢谢您的帮助!

解决方案

启动延迟可能是由CDI的隐式bean存档扫描引起的.如果您不使用CDI,则可以使用com.ibm.ws.cdi.enableImplicitBeanArchives=false禁用隐式bean归档.

您可以在此技术说明中找到更详细的说明:
用于改善WebSphere Application Server中应用程序启动的自定义属性

I've a Spring Boot Application with main class:

@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer{

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

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

    private static Class<MyApplication > applicationClass = MyApplication .class;
}

With gradle.build:

version '1.0'
// dependencies for command line
buildscript {
    ext {
        springBootVersion = '1.4.3.RELEASE'
        dependencyManagementVersion = '0.6.0.RELEASE'
    }
    repositories {
        jcenter()
    }
    dependencies {
        classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
        classpath "io.spring.gradle:dependency-management-plugin:${dependencyManagementVersion}"
    }
}

apply plugin: "io.spring.dependency-management"
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'idea'

// JDK 8
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

repositories {
    jcenter()
}

ext {
    springCloudVersion = 'Brixton.SR4'
    springBootVersion = '1.4.3.RELEASE'
    swaggerVersion = '2.4.0'
    jodaTimeVersion = '2.9.4'
    jacksonJodaVersion = '2.5.1'
    junitVersion = '4.12'
    springWsTestVersion = '2.2.3.RELEASE'
    lombokVersion = '1.16.10'
    jsonPathVersion = '2.2.0'
    ehcacheVersion = '3.2.0'
    javaxCacheVersion = '1.0.0'
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
        mavenBom "org.springframework.boot:spring-boot-starter-parent:${springBootVersion}"
    }
}

sourceSets {
    test {
        java {
            srcDir 'src/test/unit/java'
        }
        resources {
            srcDir 'src/test/unit/resources'
        }
    }
}

tasks.withType(JavaExec) {
    if (System.getProperty("DEBUG", 'false') == 'true') {
        jvmArgs '-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006'
    }
}

dependencies {
    // https://mvnrepository.com/artifact/javax/javaee-api
    compile group: 'javax', name: 'javaee-api', version: '7.0'

    /* core libraries */
    compile('org.springframework.cloud:spring-cloud-starter-config') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    compile('org.springframework.boot:spring-boot-starter-web') {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    compile("org.springframework.boot:spring-boot-starter-hateoas"){
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    compile 'org.springframework.ws:spring-ws-core'

    // tag::actuator[]; for @RefreshScope
    compile("org.springframework.boot:spring-boot-starter-actuator"){
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    // end::actuator[]
    // logging
    compile('org.springframework.boot:spring-boot-starter-log4j2')
    compile('com.fasterxml.jackson.dataformat:jackson-dataformat-yaml')
    compile('com.fasterxml.jackson.core:jackson-databind')

    // embedded server
    providedRuntime ('org.springframework.boot:spring-boot-starter-tomcat')


    // https://mvnrepository.com/artifact/org.projectlombok/lombok-maven
    compile "org.projectlombok:lombok:${lombokVersion}"

    // https://mvnrepository.com/artifact/com.jayway.jsonpath/json-path
    // A Java DSL for reading JSON documents
    compile "com.jayway.jsonpath:json-path:${jsonPathVersion}"

    //for EhCache
    // https://mvnrepository.com/artifact/org.ehcache/ehcache
    compile "org.ehcache:ehcache:${ehcacheVersion}"
    // https://mvnrepository.com/artifact/javax.cache/cache-api
    compile "javax.cache:cache-api:${javaxCacheVersion}"
    // utilities
    compile "io.springfox:springfox-swagger2:${swaggerVersion}"
    compile "io.springfox:springfox-swagger-ui:${swaggerVersion}"
    compile "joda-time:joda-time:${jodaTimeVersion}"
    compile "com.fasterxml.jackson.datatype:jackson-datatype-joda:${jacksonJodaVersion}"
    compile ("org.springframework.boot:spring-boot-starter-aop") {
        exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging'
    }
    compile "org.aspectj:aspectjweaver:1.8.8"

    /* plugins */

    /* test libraries */
    // unit
    testCompile "junit:junit:${junitVersion}"
    testCompile "org.springframework.boot:spring-boot-starter-test"
    testCompile "org.springframework.ws:spring-ws-test:${springWsTestVersion}"
}

war {
    archiveName = "${project.name}.war"
    manifest {
        attributes 'Main-Class': 'com..content.MyApplication'
    }
}

When I try to deploy the war file on WebSphere Application Server 9.0 Traditional, it starts but takes very long time. Without war file, server starts and stops very normally, but with application, server hangs.

Am I missing something?

Thank you for help!!

解决方案

The startup delay is probably caused by CDI's implicit bean archive scanning. If you are not using CDI, you can disable implicit bean archives with com.ibm.ws.cdi.enableImplicitBeanArchives=false.

You can find a much more detailed explanation in this tech note:
Custom Properties for improving application startup in WebSphere Application Server

这篇关于在WebSphere 9上运行Spring Boot Application的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆