使用Jhipster连接到Mysql

时间:2017-11-10 18:20:38

标签: spring maven spring-boot jhipster liquibase

我已经生成了一个spring boot + angular应用程序。使用jdl导入实体。与h2一起正常工作。我是新手,想要使用mysql。我已经在application-dev.yml中使用以下代码配置了数据源。

datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:mysql://localhost:3306/blogdb?useUnicode=true&characterEncoding=utf8&useSSL=false
    username: name
    password:pass
h2:
    console:
        enabled: false
     hikari:
            data-source-properties:
                cachePrepStmts: true
                prepStmtCacheSize: 250
                prepStmtCacheSqlLimit: 2048
                useServerPrepStmts: true
    jpa:
        database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    database: mysql
    show-sql: true

2)我已经使用以下代码将我的pom配置从h2更新为mysql。

<plugin>
            <groupId>org.liquibase</groupId>
            <artifactId>liquibase-maven-plugin</artifactId>
            <version>${liquibase.version}</version>
            <configuration>
                <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
                <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
                <driver>com.mysql.jdbc.Driver</driver>
                <url>jdbc:mysql://localhost:3306/blogdb</url>
                <defaultSchemaName>blogdb</defaultSchemaName>
                <username>name</username>
                <password>**</password>
                <referenceUrl>hibernate:spring:pt.farol.destfinder.domain?dialect=org.hibernate.dialect.MySQLInnoDBDialect&amp;hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy</referenceUrl>
                <verbose>true</verbose>
                <logging>debug</logging>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.javassist</groupId>
                    <artifactId>javassist</artifactId>
                    <version>${javassist.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.liquibase.ext</groupId>
                    <artifactId>liquibase-hibernate5</artifactId>
                    <version>${liquibase-hibernate5.version}</version>
                </dependency>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-data-jpa</artifactId>
                    <version>${project.parent.version}</version>
                </dependency>
                <dependency>
                    <groupId>javax.validation</groupId>
                    <artifactId>validation-api</artifactId>
                    <version>${validation-api.version}</version>
                </dependency>
            </dependencies>
        </plugin>

问题当我运行我的项目时,我遇到以下错误。

    The Class-Path manifest attribute in C:\..\..\.m2\repository\org\liquibase\liquibase-core\3.5.3\liquibase-core-3.5.3.jar referenced one or more files that do not exist: C:\..\.\.m2\repository\org\liquibase\liquibase-core\3.5.3\lib\snakeyaml-1.13.jar
22:58:49.740 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
22:58:49.751 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
22:58:49.751 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/G:/Java%20Projects/target/classes/]
22:58:52.636 [restartedMain] DEBUG org.springframework.boot.logging.ClasspathLoggingApplicationListener - Application failed to start with classpath: [file:/G:/Java%20Projects/target/classes/]

修改 git repository link

yo-rc.json档案

{
  "generator-jhipster": {
    "promptValues": {
      "packageName": "com.beam"
    },
    "jhipsterVersion": "4.10.2",
    "baseName": "beam",
    "packageName": "com.beam",
    "packageFolder": "com/beam",
    "serverPort": "8080",
    "authenticationType": "session",
    "hibernateCache": "ehcache",
    "clusteredHttpSession": false,
    "websocket": false,
    "databaseType": "sql",
    "devDatabaseType": "mysql",
    "prodDatabaseType": "mysql",
    "searchEngine": false,
    "messageBroker": false,
    "serviceDiscoveryType": false,
    "buildTool": "maven",
    "enableSocialSignIn": false,
    "enableSwaggerCodegen": false,
    "rememberMeKey": "801a22f60c33f866035c634e04c3b5b096fdedc6",
    "clientFramework": "angularX",
    "useSass": true,
    "clientPackageManager": "yarn",
    "applicationType": "monolith",
    "testFrameworks": [],
    "jhiPrefix": "jhi",
    "enableTranslation": false
  }
}

5 个答案:

答案 0 :(得分:2)

这不是答案,但我需要比评论更多的空间。

我使用您的.yo-rc.json文件和jhipster 4.10.2生成了一个应用程序,它运行正常。我也有类路径清单警告但它无害且应用程序有效。

[INFO] --- spring-boot-maven-plugin:1.5.7.RELEASE:run (default-cli) @ beam ---
[INFO] Attaching agents: []
The Class-Path manifest attribute in C:\Users\Gaël\.m2\repository\org\liquibase\liquibase-core\3.5.3\liquibase-core-3.5.3.jar referenced one or more files tha
t do not exist: C:\Users\Gaël\.m2\repository\org\liquibase\liquibase-core\3.5.3\lib\snakeyaml-1.13.jar
22:15:34.613 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
22:15:34.617 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/,

2017-11-13 22:15:57.237  INFO 20472 --- [  restartedMain] com.beam.BeamApp                         :
----------------------------------------------------------
        Application 'beam' is running! Access URLs:
        Local:          http://localhost:8180
        External:       http://172.27.112.1:8180
        Profile(s):     [swagger, dev]
----------------------------------------------------------

所以,我想你并没有粘贴真正的错误。 究竟是什么症状?

答案 1 :(得分:1)

尝试创建一个新的jhipster应用程序,并在创建时选择Mysql。它需要几分钟,你可以检查和比较。

答案 2 :(得分:1)

通常在application-dev.yml中,间距被认为是密码

你的, 数据源:     键入:com.zaxxer.hikari.HikariDataSource     url:jdbc:mysql:// localhost:3306 / blogdb?useUnicode = true&amp; characterEncoding = utf8&amp; useSSL = false     用户名:名称     密码:通 该怎么做才是,

数据源:     键入:com.zaxxer.hikari.HikariDataSource     url:jdbc:mysql:// localhost:3306 / blogdb?useUnicode = true&amp; characterEncoding = utf8&amp; useSSL = false     用户名:名称     密码:传递

看看吧

答案 3 :(得分:0)

当我尝试使用Mysql安装JHipster项目时,我遇到了同样的问题,我的问题在我更改时得到了解决

datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/blogdb?useUnicode=true&characterEncoding=utf8&useSSL=false
username: name
password:pass

datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/blogdb /*Removed the parameters*/
username: name
password:pass

答案 4 :(得分:0)

如果您使用的是docker,我也会遇到相同的错误,因此将localhost替换为您的docker IP

type: com.zaxxer.hikari.HikariDataSource
        url: jdbc:mysql://192.168.99.100:3306/library
        username: root