无法将Mysql与Spring工具套件连接?

时间:2019-05-21 10:58:33

标签: java mysql rest spring-boot dependencies

tomcat端口和mysql端口应该相同吗? 我想通过rest-apis访问mysql数据库。我无法同时打开mysql工作台和运行spring boot。是否因为两者都使用相同的端口?另外,如果我在application.properties中更改端口“ server.port = 7070”,则该项目将无法成功运行。

application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/playjava?useSSL=flase
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
server.port=3306

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>2.1.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>RestWithJPACreateProfessor</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>RestWithJPACreateProfessor</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-actuator</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-web</artifactId>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </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>

请帮助。预先谢谢你。

1 个答案:

答案 0 :(得分:0)

我必须卸载并重新安装spring工具套件和mysql。另外我还必须卸载在计算机上独立运行的tomcat,由于该原因我无法使用端口8080。这就是为什么我在spring项目和mysql中使用端口3306的原因。因此,在项目运行时,我无法同时打开mysql。