启动spring boot openshift应用程序时出错:无法启动嵌入式Tomcat

时间:2016-11-03 02:33:38

标签: spring mongodb spring-boot openshift

我已经使用这个link来创建一个带有tomcat 8&的DIY应用程序。 springboot。我修改了上面链接的代码,使其访问mongodb而不是postgres。我一直在试图找出启动示例应用程序。任何人都可以帮我解决这个错误。

.openshift / action_hooks /部署

/*BODY*/

.gr-body {
    background: url(http://orig14.deviantart.net/8b57/f/2016/279/f/5/frontpagebackground_by_wulfghast-dak5apt.jpg);
    background-size: 100%;
    background-repeat: no-repeat;
    background-color: #1c1119;
    color: #545454;

}

.gr-top{
    border: none;
    margin: -5px 0px -10px 0px;

}

.gr-top img {
    display: none;

}

h2 {
    display: none;

}

.gr-top span {
    display: none;

}

.tri {
    display: none;

}

.gr1, .gr2, .gr3 {
    display:none;

}
.bottom {
    display: none;

}

.text {
    margin-bottom: -38px;
    padding: 0;

}

/*TEXT*/

p {
    color: #3c281f;
    font-family: 'montserrat', sans-serif;
    font-size: 15px;
    line-height: 1.4;
    margin: 20px;

}

/*MENU AREA*/

.menu {
    width: 64%;
    height: 171px;
    margin-left: auto;
    margin-right: auto;
    margin-top: 18%;
    padding-left: 10%;
    background: url('http://s15.postimg.org/zby726h7v/header.png');
    background-repeat: no-repeat;
    background-position: top-center;
    background-size: 100% 70%;
    position: relative;
    z-index: 3;

}

.branchoverlay {
    width: 74%;
    height: 694px;
    margin-left: auto;
    margin-right: auto;
    margin-top: -53px;
    background: url('http://s15.postimg.org/n6ayvyzrd/branchoverlay.png');
    background-repeat: no-repeat;
    background-position: top-center;
    background-size: 100% 70%;
    position: relative;
    z-index: 2;

}

.dropdowncontainer {
    height: 30px;
    width: 70%;
    margin-left: auto;
    margin-right: auto;

}

.dropdown {
    position: relative;
    display: inline-block;
    width: 23%;
    text-align: center;
    margin-top: 30px;

}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #4a463b;
    min-width: 120px;
    padding-bottom: 20px;

}

.dropdown-content a {
    color: #ffffff;
    line-height: 2.5;

}

.dropdown-content a:hover {
   color: #000000;

}

.dropdown:hover .dropdown-content {
    display: block;
}

/*CONTENT*/

.contentholder {
    width: 68%;
    margin-left: auto;
    margin-right: auto;
    margin-top: -735px;
    -moz-box-shadow: 0 20px 20px 5px #0a0a0a;
    -webkit-box-shadow: 0 20px 20px 5px #0a0a0a;
    box-shadow: 0 20px 20px 5px #0a0a0a;
    background-color: #50463b;
    position: relative;
    z-index: 1;
}

.maindiv {
    width: 85%;
    margin-top: 4%;
    margin-left: 5%;
    margin-bottom: 400px;
    position: relative;
    z-index: 5;
    padding: 20px 20px 20px 20px;
    display: inline-block;
}

/*FOOTER*/

.rockfooter {
    background: url(http://s17.postimg.org/is79jxd3z/footer3_by_wulfghast_dakd92b_1.png);
    height: 1000px;
    width: 100%;
    background-position: bottom;
    background-repeat: no-repeat;
    background-size: contain;
    margin-left: auto;
    margin-right: auto;
    margin-top: -1100px;
    position: relative;
    z-index: 4;
}

/*RESPONSIVE MOBILE*/

.da-media[mobile] .menu {
    width: 74%;
    padding-left: 0%;

}

.da-media[mobile] .dropdown {
    margin-top: 35px;
    width: 31%;

}

.da-media[mobile] .maindiv {
    margin-left: 1%;
}

.da-media[mobile] .rockfooter {
    margin-top: -1300px;
}

开始

#!/bin/bash

set -x

if [ ! -d $OPENSHIFT_DATA_DIR/m2/repository ]
then
    mkdir -p $OPENSHIFT_DATA_DIR/m2/repository
fi

if [ ! -d $OPENSHIFT_DATA_DIR/logs ]
then
    mkdir -p $OPENSHIFT_DATA_DIR/logs
fi

if [ ! -d $OPENSHIFT_DATA_DIR/apache-maven-3.3.9 ]
then
    wget -P $OPENSHIFT_DATA_DIR http://mirror.cc.columbia.edu/pub/software/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
    tar xvf $OPENSHIFT_DATA_DIR/apache-maven*.tar.gz --directory $OPENSHIFT_DATA_DIR
    rm -f $OPENSHIFT_DATA_DIR/apache-maven*.tar.gz
fi


export JAVA_HOME=/etc/alternatives/java_sdk_1.8.0
export M2=$OPENSHIFT_DATA_DIR/apache-maven-3.3.9/bin
export MAVEN_OPTS="-Xms384m -Xmx412m"
export PATH=$JAVA_HOME/bin:$PATH

cd $OPENSHIFT_REPO_DIR


$M2/mvn --version
$M2/mvn -s settings.xml clean install

停止

#!/bin/bash

source $OPENSHIFT_CARTRIDGE_SDK_BASH

set -x

export JAVA_HOME=/etc/alternatives/java_sdk_1.8.0
export PATH=$JAVA_HOME/bin:$PATH

cd $OPENSHIFT_REPO_DIR
nohup java -Xms384m -Xmx412m -jar target/*.jar --server.port=${OPENSHIFT_DIY_PORT} --server.address=${OPENSHIFT_DIY_IP} --spring.profiles.active=openshift &

的pom.xml

#!/bin/bash

source $OPENSHIFT_CARTRIDGE_SDK_BASH

PID=$(ps -ef | grep java.*\.jar | grep -v grep | awk '{ print $2 }')

if [ -z "$PID" ]
then
    client_result "Application is already stopped"
else
    kill $PID
fi

application-openshift.properties

<?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>org.test</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

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

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

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </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-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-mongodb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <start-class>demo.Application</start-class>
        <java.version>1.8</java.version>
        <tomcat.version>8.0.9</tomcat.version>
    </properties>

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

</project>

openshift控制台出错

spring.datasource.url = jdbc:mongodb://${OPENSHIFT_MONGODB_DB_HOST}:${OPENSHIFT_MONGODB_DB_PORT}/${OPENSHIFT_APP_NAME}
spring.datasource.username = ${OPENSHIFT_MONGODB_DB_USERNAME}
spring.datasource.password = ${OPENSHIFT_MONGODB_DB_PASSWORD}

logging.file = ${OPENSHIFT_DATA_DIR}/logs/app.log
logging.level. = INFOgi

更新

我将springboot版本更新为1.4.1.RELEASE,现在异常是不同的。它抱怨嵌入式容器

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat        
remote:     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) ~[spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532) ~[spring-context-4.2.7.RELEASE.jar!/:4.2.7.RELEASE]        
remote:     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) ~[spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:760) [spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:360) [spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.boot.SpringApplication.run(SpringApplication.java:306) [spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1185) [spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.boot.SpringApplication.run(SpringApplication.java:1174) [spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at demo.Application.main(Application.java:10) [demo-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]        
remote:     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_111]        
remote:     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_111]
remote:     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_111]        
remote:     at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_111]        
remote:     at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:54) [demo-0.0.1-SNAPSHOT.jar!/:0.0.1-SNAPSHOT]        
remote:     at org.springframework.boot.loader.Launcher.launch(Launcher.java:104) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]        
remote:     at org.springframework.boot.loader.Launcher.launch(Launcher.java:61) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]        
remote:     at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) [demo-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]        
remote: Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat        
remote:     at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:99) ~[spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:76) ~[spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:457) ~[spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:168) ~[spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:160) ~[spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) ~[spring-boot-1.3.6.RELEASE.jar!/:1.3.6.RELEASE]        
remote:     ... 16 common frames omitted        
remote: Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.boot.autoconfigure.web.HttpMessageConverters org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.messageConverters; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private final java.util.List org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration.converters; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mappingJackson2HttpMessageConverter' defined in class path resource [org/springframework/boot/autoconfigure/web/JacksonHttpMessageConvertersConfiguration$MappingJackson2HttpMessageConverterConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [com.fasterxml.jackson.databind.ObjectMapper]: Error creating bean with name 'objectMapper' defined in class path resource [org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'objectMapper' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'config' defined in class path resource [org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.config.RepositoryRestConfiguration]: Factory method 'config' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceMappings' defined in class path resource [org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.mapping.ResourceMappings]: Factory method 'resourceMappings' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistentEntities' defined in class path resource [org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mapping.context.PersistentEntities]: Factory method 'persistentEntities' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "openshift" are currently active).; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapper' defined in class path resource [org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.databind.ObjectMapper]: Factory method 'objectMapper' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'config' defined in class path resource [org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.config.RepositoryRestConfiguration]: Factory method 'config' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceMappings' defined in class path resource [org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.mapping.ResourceMappings]: Factory method 'resourceMappings' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'persistentEntities' defined in class path resource [org/springframework/boot/autoconfigure/data/rest/SpringBootRepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.mapping.context.PersistentEntities]: Factory method 'persistentEntities' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMappingContext': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "openshift" are currently active). 

1 个答案:

答案 0 :(得分:0)

  

无法确定数据库类型为NONE的嵌入式数据库驱动程序类。如果你想要一个嵌入式数据库,请在类路径上放置一个受支持的数据库。如果要从特定配置文件加载数据库设置,则可能需要激活它(配置文件“openshift”当前处于活动状态)。

您正在尝试使用数据库,但尚未向Spring Boot提供任何相关信息以连接到它。 Spring Boot 1.3.x不支持Mongo 3.x,need to upgrade to Spring Boot 1.4 first