当前位置: 首页 > 知识库问答 >
问题:

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

郭逸清
2023-03-14

运行Spring Boot应用程序时,嵌入式tomcat服务器无法启动。我刚刚在pom.xml中添加了所需的依赖项,并创建了一个简单的java POJO类。应用程序属性已经按照oracle数据库所需的jdbc配置以及Hibernate方言信息进行了设置。

#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

<?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>


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个答案

韦晟睿
2023-03-14

向pom添加Web依赖项

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

如果没有这个,你的应用程序就会停止,因为它已经完成了...

 类似资料: