java – 无法将简单的Spring Boot Web应用程序部署到OpenShift

前端之家收集整理的这篇文章主要介绍了java – 无法将简单的Spring Boot Web应用程序部署到OpenShift前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个.war文件,当我复制到我的Tomcat 9本地实例中的webapps文件夹时,它会成功部署.不知何故,当我尝试在Openshift齿轮(Tomcat 7)上运行它时,它不会被部署.我正在采取的步骤:

0:我克隆了远程存储库.

1:我将war文件复制到git repository中的webapps文件夹.

2:我把它推到远程仓库,我得到输出

Writing objects: 100% (5/5),4.50 KiB | 0 bytes/s,done.
Total 5 (delta 3),reused 0 (delta 0)
remote: Stopping jbossews cartridge
remote: Sending SIGTERM to jboss:341147 ...
remote: Building git ref 'master',commit 90c82a4
remote: Skipping Maven build due to absence of pom.xml
remote: Preparing build for deployment
remote: Deployment id is a9215a94
remote: Activating deployment
remote: Starting jbossews cartridge
remote: Found 127.12.55.129:8080 listening port
remote: -------------------------
remote: Git Post-Receive Result: success
remote: Activation status: success
remote: Deployment completed with status: success

>在repo中有一个我删除的.pom文件和src文件夹.

项目pom:

<?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.tomek.example</groupId>
    <artifactId>SimpleApp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>SimpleApp</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.0.RELEASE</version>
    </parent>

    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <repositories>
        <repository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>spring-releases</id>
            <url>https://repo.spring.io/libs-release</url>
        </pluginRepository>
    </pluginRepositories>

<!--    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>-->


</project>

主要java:

@SpringBootApplication
@ComponentScan({"controllers","rest"})
public class SimpleAppApplication extends SpringBootServletInitializer{

    public static void main(String[] args) {
        ConfigurableApplicationContext ctx = SpringApplication.run(SimpleAppApplication.class,args);

    }

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

    private static final Class<SimpleAppApplication> applicationClass = SimpleAppApplication.class;

}

根控制器:

@RestController
public class MainController {


    @RequestMapping("/")
    public String text (){
        return "ja pierdole wygral jebany!";
    }

}

编辑
我检查了服务器日志,我得到了很多这种类型的错误

SEVERE: Unable to process Jar entry [javassist/ByteArrayClassPath.class] from Jar [jar:jndi:/localhost/Simple/WEB-INF/lib/javassist-3.20.0-GA.jar!/] for annotations
java.io.EOFException
        at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:340)
        at org.apache.tomcat.util.bcel.classfile.Utility.swallowMethodParameters(Utility.java:796)
        at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:171)
        at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.<init>(FieldOrMethod.java:57)
        at org.apache.tomcat.util.bcel.classfile.Method.<init>(Method.java:71)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:267)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:127)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2058)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1934)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1900)
        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1885)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1317)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

** Tomcat记录**

Oct 07,2016 1:18:32 PM org.apache.catalina.startup.Catalina addClusterRuleSet
INFO: Cluster RuleSet not found due to [java.lang.ClassNotFoundException: org.apache.catalina.ha.ClusterRuleSet]. Cluster configuration disabled.
Oct 07,2016 1:18:33 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: :/usr/java/packages/lib/i386:/lib:/usr/lib
Oct 07,2016 1:18:33 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-127.9.153.1-8080"]
Oct 07,2016 1:18:33 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 1763 ms
Oct 07,2016 1:18:34 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Oct 07,2016 1:18:34 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Oct 07,2016 1:18:34 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deploying web application archive /var/lib/openshift/57efecb17628e18e59000032/app-root/runtime/dependencies/jbossews/webapps/ROOT.war
Oct 07,2016 1:18:47 PM org.apache.catalina.startup.ContextConfig processAnnotationsJar
SEVERE: Unable to process Jar entry [javassist/ByteArrayClassPath.class] from Jar [jar:jndi:/localhost/WEB-INF/lib/javassist-3.20.0-GA.jar!/] for annotations
java.io.EOFException
        at java.io.DataInputStream.readUnsignedShort(DataInputStream.java:340)
        at org.apache.tomcat.util.bcel.classfile.Utility.swallowMethodParameters(Utility.java:796)
        at org.apache.tomcat.util.bcel.classfile.Attribute.readAttribute(Attribute.java:171)
        at org.apache.tomcat.util.bcel.classfile.FieldOrMethod.<init>(FieldOrMethod.java:57)
        at org.apache.tomcat.util.bcel.classfile.Method.<init>(Method.java:71)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.readMethods(ClassParser.java:267)
        at org.apache.tomcat.util.bcel.classfile.ClassParser.parse(ClassParser.java:127)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2058)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsJar(ContextConfig.java:1934)
        at org.apache.catalina.startup.ContextConfig.processAnnotationsUrl(ContextConfig.java:1900)
        at org.apache.catalina.startup.ContextConfig.processAnnotations(ContextConfig.java:1885)
        at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1317)
        at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:876)
        at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:374)
        at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
        at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5355)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1083)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1880)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask.run(FutureTask.java:262)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)


很多相同的例外

Oct 07,2016 1:18:52 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-127.9.153.1-8080"]
Oct 07,2016 1:18:52 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 18101 ms

解决方法

现在看到四个问题:

>依赖org.javassist

mvn依赖:树显示

[INFO] \- org.springframework.boot:spring-boot-starter-thymeleaf:jar:1.4.1.RELEASE:compile
[INFO]    +- org.thymeleaf:thymeleaf-spring4:jar:2.1.5.RELEASE:compile
[INFO]    |  +- org.thymeleaf:thymeleaf:jar:2.1.5.RELEASE:compile
[INFO]    |  |  +- ognl:ognl:jar:3.0.8:compile
[INFO]    |  |  +- org.javassist:javassist:jar:3.20.0-GA:compile (version managed from 3.16.1-GA)
[INFO]    |  |  \- org.unbescape:unbescape:jar:1.1.0.RELEASE:compile
[INFO]    |  \- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO]    \- nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect:jar:1.4.0:compile
[INFO]       \- org.codehaus.groovy:groovy:jar:2.4.7:compile (version managed from 2.4.3)

这种依赖来自spring-boot-starter-thymeleaf

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.javassist</groupId>
    <artifactId>javassist</artifactId>
    <version>3.17.1-GA</version>
</dependency>

由于OpenShift Tomcat Processing Annotations Error Deploying War

> Tomcat版本

可以通过pom.xml中的属性更改Tomcat版本

<properties>
        <java.version>1.7</java.version>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
        <start-class>com.example.SimpleAppApplication</start-class>
        <tomcat.version>7.0.54</tomcat.version>
    </properties>

> OpenShift java版

由于https://developers.openshift.com/servers/tomcat/getting-started.html#other,检查OpenShift git repo上是否存在标记文件.openshift / markers / java7

您可以选择添加标记.openshift / markers / skip_maven_build来跳过maven构建.

>加载控制器

如果PagesController.java在控制器包上

@Configuration
    @EnableAutoConfiguration
    @ComponentScan("controllers")
    @RestController
    public class SimpleAppApplication extends SpringBootServletInitializer {

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

        public static void main(String[] args) {
            SpringApplication.run(SimpleAppApplication.class,args);
        }
    }
原文链接:https://www.f2er.com/java/120886.html

猜你在找的Java相关文章