Replace hsqldb with MySQL

2019-05-29 07:20发布

I have a Spring REST project configured with hsqldb. I would like to change it to MySQL. I have MySQL server installed and running, but I don't know how to modify this pom:

    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>runtime</scope>
    </dependency>

PS.: Project im talking about comes as a source code for 'Spring REST' book: http://www.apress.com/9781484208243

source code download link:

http://www.apress.com/downloadable/download/sample/sample_id/1704/

1条回答
劳资没心,怎么记你
2楼-- · 2019-05-29 07:45

As far I see you are using Spring Boot on this, so you can easy change the databases changing the drivers dependencies from:

 <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <scope>runtime</scope>
</dependency>

To

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>

The driver version will be version on parent pom. Then specify the parameters on properties

spring.datasource.url=jdbc:mysql://localhost:port/yourdb
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Driver # we can ommit this if we want, Spring Boot will deduce based on the classpath

For more configuration on databases you can see the properties available on appendix here

查看更多
登录 后发表回答