基于环境变量的Spring Boot自动配置

据我了解,在Spring-boot应用程序中,当classpath和 mysql-connector 上都装有spring-boot-starter-data-jpa时 如果未定义与数据库相关的属性, spring-boot 仍将尝试在内存h2中使用(默认情况下)。

但是如果您具有以下属性:

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/db_example
spring.datasource.username=springuser
spring.datasource.password=ThePassword

它将使用mysql数据库。

我的问题是: 如果您仅将那些属性声明为环境变量,该怎么办? 这种行为仍然有效吗?

谢谢!

a665362 回答:基于环境变量的Spring Boot自动配置

我尝试一起使用以下依赖项:“ web”,“ mysql”,“ jpa”。没有任何配置的简单运行将显示以下错误:

<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/jquery.validate.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.12.0/additional-methods.js"></script>

<form id="myForm" method="post">
  <label for="nameQuery">Name Query: </label>
  <input class="mygroup" id="nameQuery" name="nameQuery">
  </br>
  <label for="companyId">Company Id: </label>
  <input class="mygroup" id="companyId" name="companyId">
  </br>
  <input type="submit" value="Search">
  <p></p>
</form>

如果您使用环境路由而不是“ application.properties”,只要您正确设置它们,它就应与完全配置的“ application.properties”文件一样。

本文链接:https://www.f2er.com/3094849.html

大家都在问