在Spring Boot中更新应用程序的配置

时间:2018-06-08 07:19:12

标签: java spring-boot spring-hateoas

运行Spring Boot应用程序时,在Spring Boot错误中更新应用程序的配置。

maven已成功构建,但错误仍然存​​在。

如何更改克服此错误?

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::             (v2.0.0.M4)

2018-06-08 12:45:36.422  INFO 8904 --- [           main] com.lankydan.Application                 : Starting Application on GH-6C9HNH2 with PID 8904 (C:\Users\E080978\Downloads\Maven\spring-boot-hateoas-master\target\classes started by E080978 in C:\Users\E080978\Downloads\Maven\spring-boot-hateoas-master)
2018-06-08 12:45:36.426  INFO 8904 --- [           main] com.lankydan.Application                 : No active profile set, falling back to default profiles: default
2018-06-08 12:45:36.484  INFO 8904 --- [           main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@2805c96b: startup date [Fri Jun 08 12:45:36 IST 2018]; root of context hierarchy
2018-06-08 12:45:37.897  INFO 8904 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$3a19c841] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-06-08 12:45:38.652  INFO 8904 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8090 (http)
2018-06-08 12:45:38.672  INFO 8904 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2018-06-08 12:45:38.673  INFO 8904 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.20
2018-06-08 12:45:38.818  INFO 8904 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2018-06-08 12:45:38.818  INFO 8904 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 2337 ms
2018-06-08 12:45:39.020  INFO 8904 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean  : Mapping servlet: 'dispatcherServlet' to [/]
2018-06-08 12:45:39.025  INFO 8904 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-06-08 12:45:39.025  INFO 8904 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-06-08 12:45:39.026  INFO 8904 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-06-08 12:45:39.026  INFO 8904 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean   : Mapping filter: 'requestContextFilter' to: [/*]
2018-06-08 12:45:39.075  WARN 8904 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Unsatisfied dependency expressed through method 'dataSource' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.datasource-org.springframework.boot.autoconfigure.jdbc.DataSourceProperties': Could not bind properties to 'DataSourceProperties': prefix=spring.datasource, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.password' to java.lang.String
2018-06-08 12:45:39.077  INFO 8904 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-06-08 12:45:39.098  INFO 8904 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-06-08 12:45:39.103 ERROR 8904 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Binding to target [Bindable@6bff19ff type = java.lang.String, value = 'provided', annotations = array<Annotation>[[empty]]] failed:

    Property: spring.datasource.password
    Value: ${password}
    Origin: class path resource [application.properties]:7:28
    Reason: Could not resolve placeholder 'password' in value "${password}"

Action:

Update your application's configuration

3 个答案:

答案 0 :(得分:0)

您似乎没有在'spring.datasource.password'属性中尝试使用属性'password'(或者它的声明有问题)。 但是,如果没有看到整个属性文件,很难说。

答案 1 :(得分:0)

您必须打开maven资源插件的过滤功能。您必须在POM中添加<filtering>标记,并将其设置为true

在“流程资源”阶段,maven可能需要使用真实密码替换${password}变量

有关详细信息,请参阅:

https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

答案 2 :(得分:0)

错误是因为您的应用程序找不到环境变量 password。如果这个问题只发生在你的本地机器上,当 env var 不存在时,只需指定一个默认值。像这样:

spring.datasource.password: ${password:local-password}

(将 local-password 更改为您本地数据库的真实密码。)

如果它发生在您的测试或生产环境中,您必须将其注入到您服务器的环境变量中,或者联系 DevOps 人员来帮助您执行此操作。