在Spring Boot应用程序中使用自定义数据源URL的问题

时间:2019-10-01 10:59:38

标签: java spring-boot jdbc

我正在尝试运行Spring Boot应用并使用Docker运行的PostgreSQL服务。 当我在Windows上运行Docker时,它将docker-machine IP设置为192.168.99.101,这意味着我必须在我的application.properties文件中指定它:

server.port=8082
server.servlet.context-path=/

spring.datasource.url=jdbc:postgresql://192.168.99.101:5432/app_db
spring.datasource.username=postgres
spring.datasource.password=example

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update

但是,当我这样做时,它将开始显示引导登录模板作为索引页,而不是我的src / resources / templates中的模板。在postrgreSQL实施之前,它显示正确的页面。任何想法spring.datasource.url可能与实际资源路径有关?

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 https://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>2.1.8.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>ru.todolist</groupId>
    <artifactId>todoList</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>todoList</name>
    <description>Spring Boot app</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>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-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>

0 个答案:

没有答案