【问题标题】:Replace hsqldb with MySQL用 MySQL 替换 hsqldb
【发布时间】:2015-11-18 00:55:32
【问题描述】:

我有一个使用 hsqldb 配置的 Spring REST 项目。 我想将其更改为 MySQL。 我已经安装并运行了 MySQL 服务器,但我不知道如何修改这个 pom:

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

PS.:我谈论的项目是“Spring REST”书的源代码: http://www.apress.com/9781484208243

源码下载链接:

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

【问题讨论】:

    标签: mysql spring rest maven


    【解决方案1】:

    据我所知,您在此使用 Spring Boot,因此您可以轻松更改数据库,更改驱动程序依赖项:

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

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

    驱动版本将是父 pom 上的版本。 然后在属性上指定参数

    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
    

    有关数据库的更多配置,您可以在附录here 中查看可用属性

    【讨论】:

    • 谢谢老兄,你让我开心!
    猜你喜欢
    • 2011-07-06
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 2012-02-06
    • 2012-03-27
    • 1970-01-01
    相关资源
    最近更新 更多