为本地主机配置spring.datasource

时间:2020-05-01 22:59:14

标签: mysql hibernate spring-boot http spring-data-jpa

尝试在本地主机上运行Spring Boot Web应用程序并获得奇怪的结果。运行时,导航至localhost:8080会显示一个登录页面,这似乎是我的应用程序的登录页面?除了我的本地mysql数据库中存储的所有凭据之外,没有其他凭据。手动向数据库中插入新凭据也不起作用。

甚至陌生的人,该网站在chrome标签上都有Vaadin徽标,并显示“带有Spring的Vaadin Flow项目基础”安装提示。我在此项目中根本没有使用Vaadin,但是当我停止在IDE中运行该项目时,localhost:8080不会显示登录页面(但仍具有Vaadin徽标和提示)。我认为这是一种Chrome Cookie /本地缓存的废话,但是清除浏览数据并没有任何作用。我想确保其他一些localhost应用程序不在后台运行。

如果我在运行项目的情况下转到localhost:3306(正在运行mysql端口),则会在Chrome中看到ERR_INVALID_HTTP_RESPONSE,而在Edge中会得到:

J 5.7.29¨~+=@aA0ÿÿÿÁaprZfG=o87mysql_native_password!ÿ„#08S01Got packets out of order

如果我在IDE中停止该项目并刷新页面,而不是出现预期的“无法访问此站点”错误,则得到的结果与运行项目时的结果相同。

application.properties文件(我尝试了spring数据源url的两个变体,但没有发现不同):

#spring.datasource.url=jdbc:mysql://localhost:3306/tictactoe?useSSL=false
spring.datasource.url=jdbc:mysql://localhost/tictactoe
spring.datasource.username=root
spring.datasource.password=pwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.jpa.hibernate.ddl-auto=create
spring.jpa.database-platform=org.hibernate.dialect.MySQL57Dialect
spring.jpa.generate-ddl=true
spring.jpa.show-sql=true

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.2.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>spring-boot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>spring-boot</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>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

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

        <!--
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <version>42.2.12</version>
        </dependency>
        -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.192</version>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>16.0.1</version>
        </dependency>
    </dependencies>

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

</project>

0 个答案:

没有答案