Spring Boot服务器无法启动嵌入式Tomcat服务器

时间:2019-05-24 17:35:54

标签: oracle maven spring-boot application.properties

运行Spring Boot应用程序时,嵌入式tomcat服务器无法启动。我刚刚在pom.xml中添加了必需的依赖项,并创建了一个简单的Java POJO类。已根据Oracle数据库的要求,使用必需的jdbc配置以及Hibernate Dialect信息来设置应用程序属性。

spring boot尝试启动服务器并立即将其关闭。在控制台中没有发现错误。

我已经检查并验证了jdbc的url,用户名和密码是否正确,因为如果我不正确地传递它们,我会发现另一个错误。

application.properties文件

#Properties for Oracle connection using Java config
oracle.username=XXXX
oracle.password=XXXX
oracle.url=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=host.oracle.com)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=host.oracle.com)))


spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
spring.jpa.hibernate.ddl-auto=none

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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.21.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.app.oracle</groupId>
    <artifactId>OMBugDBAnalyzer</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>OMBugDBAnalyzer</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>com.oracle</groupId>
            <artifactId>ojdbc7</artifactId>
            <version>12.1.0.1</version>
        </dependency>

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

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

</project>


DBConfig.java

package com.app.oracle.OMBugDBAnalyzer.config;

import oracle.jdbc.pool.OracleDataSource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.sql.DataSource;
import java.sql.SQLException;

@Configuration
@ConfigurationProperties("oracle")
public class DBConfig {

    private String username;

    private String password;

    private String url;

    public void setUsername(String username) {
        this.username = username;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    @Bean
    DataSource dataSource() throws SQLException {

        OracleDataSource dataSource = new OracleDataSource();
        dataSource.setUser(username);
        dataSource.setPassword(password);
        dataSource.setURL(url);
        dataSource.setImplicitCachingEnabled(true);
        dataSource.setFastConnectionFailoverEnabled(true);
        return dataSource;
    }



}

我执行mvn spring-boot:run时的控制台日志

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v1.5.21.RELEASE)

2019-05-24 22:59:17.866  INFO 3704 --- [           main] c.a.o.O.OmBugDbAnalyzerApplication       : Starting OmBugDbAnalyzerApplication on vijswami-mac with PID 3704 (/MyExperiments/OMBugDBAnalyzer/target/classes started by vijswami in /MyExperiments/OMBugDBAnalyzer)
2019-05-24 22:59:17.869  INFO 3704 --- [           main] c.a.o.O.OmBugDbAnalyzerApplication       : No active profile set, falling back to default profiles: default
2019-05-24 22:59:17.906  INFO 3704 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@7b11b270: startup date [Fri May 24 22:59:17 IST 2019]; root of context hierarchy
2019-05-24 22:59:23.439  INFO 3704 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-05-24 22:59:23.455  INFO 3704 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2019-05-24 22:59:23.525  INFO 3704 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2019-05-24 22:59:23.526  INFO 3704 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2019-05-24 22:59:23.528  INFO 3704 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2019-05-24 22:59:23.563  INFO 3704 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-05-24 22:59:28.449  INFO 3704 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
2019-05-24 22:59:35.367  INFO 3704 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-05-24 22:59:35.559  INFO 3704 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-05-24 22:59:35.568  INFO 3704 --- [           main] c.a.o.O.OmBugDbAnalyzerApplication       : Started OmBugDbAnalyzerApplication in 17.906 seconds (JVM running for 20.542)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  19.608 s
[INFO] Finished at: 2019-05-24T22:59:35+05:30
[INFO] ------------------------------------------------------------------------
2019-05-24 22:59:35.573  INFO 3704 --- [       Thread-4] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@7b11b270: startup date [Fri May 24 22:59:17 IST 2019]; root of context hierarchy
2019-05-24 22:59:35.574  INFO 3704 --- [       Thread-4] o.s.j.e.a.AnnotationMBeanExporter        : Unregistering JMX-exposed beans on shutdown
2019-05-24 22:59:35.574  INFO 3704 --- [       Thread-4] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'

1 个答案:

答案 0 :(得分:1)

为您的pom添加网络依赖性

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

否则,您的应用程序将停止,因为它已完成...