こんにちは私は一般的にMavenを使い慣れていないので、間違っていたら事前にお詫びしたいと思います。SpringでMavenプロパティにアクセスできない
私はMySQLデータベースにアクセスする春のMavenプロジェクトを持っています。
多くの場合、MySQLデータベースにアクセスできないため、テスト用にローカルデータベースを使用します。アクティブなプロファイルを変更して2つのデータベースを交換します。
私は私のpom.xmlでこれを置くことによってプロファイルを設定:
<profiles>
<profile>
<id>Local</id>
<dependencies>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.3</version>
<classifier>jdk5</classifier>
</dependency>
</dependencies>
<properties>
<jdbc.url>jdbc:hsqldb:file:databaseName</jdbc.url>
<jdbc.username>a</jdbc.username>
<jdbc.password></jdbc.password>
<jdbc.driver>org.hsqldb.jdbcDriver</jdbc.driver>
</properties>
</profile>
<profile>
<id>MySQL</id>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.38</version>
</dependency>
</dependencies>
<properties>
<jdbc.url>jdbc:mysql://mysql.website.ac.uk:3306</jdbc.url>
<jdbc.username>user</jdbc.username>
<jdbc.password>1234</jdbc.password>
<jdbc.driver>com.mysql.jdbc.Driver</jdbc.driver>
</properties>
</profile>
</profiles>
私は、彼らが実際の値に変換されない例$ {jdbc.url}のプロパティに変数を介してアクセスしてみてください
プロファイルに定義されているように、私はエラーが発生します。私はそれがSpring Bootと何か関係があるかもしれないと思う。
デバッグログと詳細ログを有効にして、何が起きているのかを確認しようとしましたか? – randominstanceOfLivingThing
あなたの質問には関係ありませんが、pom.xmlにデータベースプロパティを設定することは悪い考えです。 Github、bitbucketなどの外部VCSにコードを保存していますか? – Everv0id
POM – Priyamal