Failed to bind properties under 'server' to org.springframework.boot.autoconfigure.web.ServerProperties: - spring-boot

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-09-04 12:23:24.383 ERROR 12320 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'server' to org.springframework.boot.autoconfigure.web.ServerProperties:
Property: server
Value:
Origin: class path resource [application.properties]:2:0
Reason: No converter found capable of converting from type [java.lang.String] to type [#org.springframework.boot.context.properties.ConfigurationProperties org.springframework.boot.autoconfigure.web.ServerProperties]
Action:
Update your application's configuration
My application.properties file look like this:
server:
port: ${PORT:9191}
spring:
datasource:
url: jdbc:sqlserver://PC382682:1433;databaseName=imvenkat
username: imvenkat
password: imvenkat
driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
I know the issue is related to Spring boot, but how should I change my application.properties file to address this issue?

The problem is that you're using YAML format within a properties file. The properties are being parsed line by line, so the properties parser reads server:, and doesn't know how to bind to server directly, which causes the error you see.
Either rename your file to application.yml or change the properties:
server.port=${PORT:9191}
spring.datasource.url=jdbc:sqlserver://PC382682:1433;databaseName=imvenkat
spring.datasource.username=imvenkat
spring.datasource.password=imvenkat
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver

This Error can occur when there is mis match between parent version and your spring-boot-devtools dependency.
Remove the version from spring-boot-devtools dependency, that will solve the issue.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>

This error can also occur if your config file is in yaml format but you have an error in your yaml so one line looks like a property. Happened to me, previous this was just a broken configuration line, now it breaks the application.
So if you have something broken (look at the url=) like:
server:
port: ${PORT:9191}
spring:
datasource:
url=jdbc:sqlserver://PC382682:1433;databaseName=imvenkat
the same cryptic error can occur. Fixing the config line fixes this error.

Related

Spring Boot- Profile setting Through YML file is not working

In Spring Boot program, profile setting using application.yml is not working whereas the same program is working using applicaiton.properties. the following actions has been performed but it ended up in vain
In Eclipse ide Project-Clean has been done
Maven project updated
Spaces in YML file removed and corrected
YML file is deleted and recreated.
applicaiton.yml
spring:
profiles:
active: dev
applicaiton-dev.yml
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql:///ntspbms616db
username: root
password: root
dbcp2:
max-total: 100
initial-size: 10
max-conn-lifetime-millis: 10000000
type: org.apache.commons.dbcp2.BasicDataSource
The error i got after running the program is
Enter the Employee Name
Raja
Enter the Employee Designation
Manager
Enter the Basic Salary
9898999
12:28:40.622 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
found character '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation)
in 'reader', line 4, column 2:
How to resolve the issue?
This error means literally what is says.
The "tab" is not permitted by the YAML specs:
To maintain portability, tab characters must not be used in
indentation, since different systems treat tabs differently. Note that
most modern editors may be configured so that pressing the tab key
results in the insertion of an appropriate number of spaces.
So, you should double check for the tab characters in your yaml files and if exist, replace them by double space.
Also, just to add, I can see incorrect formatting of dbcp2 section, without any intendation, so, it should look like this:
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql:///ntspbms616db
username: root
password: root
dbcp2:
max-total: 100
initial-size: 10
max-conn-lifetime-millis: 10000000
type: org.apache.commons.dbcp2.BasicDataSource

encrypt key Property binding error in spring boot 2.7.0

I have Spring boot 2.7.0 application which connects config server with following configuration to decrypt secrets. But when I include below configuration in (application.yml or bootstrap.yml) getting binding error. Not sure what is the root cause of this issue as format is correct for the keys but still getting this error. Same config is working fine with Spring boot 2.2.1.
I have used same config in application.yml without bootstrap.yml as it depricated in 2.7.0 but still same issue.
encrypt:
key-store:
location: file:${key.path}
password: anthem$$docker
alias: docker
secret: anthem$$docker
org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'encrypt.key-store.alias' to java.lang.String
at org.springframework.boot.context.properties.bind.Binder.handleBindError(Binder.java:384)
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:344)
at org.springframework.boot.context.properties.bind.Binder.lambda$bindDataObject$4(Binder.java:469)
at org.springframework.boot.context.properties.bind.Binder$$Lambda$78/234145890.bindProperty(Unknown Source)
at org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:95)
at org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:83)
at org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:59)
at org.springframework.boot.context.properties.bind.Binder.lambda$bindDataObject$5(Binder.java:473)
Description:
Failed to bind properties under 'encrypt.key-store.alias' to java.lang.String:
Property: encrypt.key-store.alias
Value: docker
Origin: class path resource [bootstrap.yml] - 40:12
Reason: org.springframework.boot.context.config.InactiveConfigDataAccessException: Inactive property source 'Config resource 'class path resource [bootstrap.yml]' via location 'optional:classpath:/' (document #5)' imported from location 'class path resource [bootstrap.yml]' cannot contain property 'encrypt.key-store.alias' [origin: class path resource [bootstrap.yml] - 40:12]
Action:
Update your application's configuration

am trying a Spring boot example but it is showing following error.. what should i do?

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-26 11:37:05.248 ERROR 9332 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:175)
The following method did not exist:
org.apache.tomcat.util.modeler.Registry.disableRegistry()V
The method's class, org.apache.tomcat.util.modeler.Registry, is available from the following locations:
jar:file:/C:/Program%20Files/Java/jre1.8.0_77/lib/ext/tomcat-coyote.jar!/org/apache/tomcat/util/modeler/Registry.class
jar:file:/C:/Users/hp/.m2/repository/org/apache/tomcat/embed/tomcat-embed-core/9.0.31/tomcat-embed-core-9.0.31.jar!/org/apache/tomcat/util/modeler/Registry.class
It was loaded from the following location:
file:/C:/Program%20Files/Java/jre1.8.0_77/lib/ext/tomcat-coyote.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.apache.tomcat.util.modeler.Registry
please put some of your code snippet here, such as application.properties file, main and ... . or you can push your application to github and put your repository address here then i'll check it.

Spring Boot not loading keystore specified in application.yml

I am attempting to run and test a Spring Boot application that I have packaged into a zip file and unpacked on a Linux VM. The zip contains everything the application needs (at least to my knowledge). When I attempt to execute the application, it starts but quickly fails because it cannot load a keystore needed for SSH/TLS secure communications.
I have the following in my application.yml:
server:
port: 8091
ssl:
enabled: true
protocol: TLS
trust-store-type: JKS
trust-store: classpath:keystore/server.keystore
trust-store-password: <hidden>
key-store-type: JKS
key-store: classpath:keystore/ra/server.keystore
key-store-password: <hidden>
The directory structure on the test system is as follows:
[centos#route-assessor route-assessor]$ ls -R
.:
config elastic-apm-agent-1.10.0.jar lib run-route-assessor.sh services-0.0.1-SNAPSHOT.jar
./config:
application.yml keystore log4j2.xml
./config/keystore:
mp ra rg server.keystore
./config/keystore/mp:
server.keystore
./config/keystore/ra:
server.keystore
./config/keystore/rg:
server.keystore
./lib
<dependency jars>
Here is the exception thrown:
[2019-10-23 13:21:31.419] main WARN : context.AnnotationConfigServletWebServerApplicationContext:557 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Could not load key store 'classpath:keystore/server.keystore'
The Spring Boot "runtime" obviously sees and accesses the config directory, but doesn't seem to see the keystore directory contained within. Do I need to specify the paths differently in application.yml or do I need to put the keystore files somewhere else?
Note: I can run this application with the application.yml configured as shown from eclipse without any problem. Granted, all resources are located in src/main/resources for that situation.
UPDATE:
As per #borban's suggestion, I modified the application.yml as follows:
key-store: file:config/keystore/ra/server.keystore
trust-store: file:config/keystore/server.keystore
That seems to have solved one problem, but I'm not out of the woods yet:
[2019-10-23 15:07:17.671] main ERROR: boot.SpringApplication:821 - Application run failed
org.springframework.boot.web.server.WebServerException: Unable to start embedded Jetty server
...
Caused by: java.lang.IllegalStateException: no valid keystore
...
As far as I know, my keystore files are valid and correct (I've been using them on my Windows development box for months). They are copied over as part of the zip distribution. Is there something maybe I'm missing?
I'm also a little concerned with a few other messages in the log. I'm not sure if they're related, but it seems that they could be:
[2019-10-23 15:07:10.153] main WARN : resource.Resource:126 - java.lang.IllegalArgumentException: URI is not hierarchical
[2019-10-23 15:07:10.155] main WARN : resource.Resource:126 - java.lang.IllegalArgumentException: URI is not hierarchical
I don't recall seeing them before.
Are you are trying to access this keystore outside of the classpath and from the filesystem itself? From the folder structure you are giving, that seems to be the case. If you remove the "classpath" prefix and then update your path appropriately, it should work.
From this post, it looks like you have to prefix with "file"
https://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html
You can use maven resource plugin to add the folders you need to the plugin:
https://maven.apache.org/plugins/maven-resources-plugin/examples/resource-directory.html
then use without classpath??

DataValidationException when I create actuator endpoints

I have created Actuator endpoints in endpoints.yml file
info:
'#name#':
version: '#version#'
buildNumber: '#buildNumber#'
buildDate: '#buildDate#'
buildBranch: '#buildBranch#'
When I try to execute I am getting a weird error:
{"errorType":"NOT_FOUND","entity":null,"message":"No message available","fieldErrors":null}
In the console it says
c.c.c.errors.BaseControllerAdvice - An unhandled exception was thrown, returning 500
org.springframework.data.rest.webmvc.ResourceNotFoundException: Resource not found!
Expected output looks like
{"${spring":{"application":{"name}":{"version":"#version#","buildNumber":"#buildNumber#","buildDate":"#buildDate#","buildBranch":"#buildBranch#"}}}}
What might be causing this Error?
I have added Dependency in order to enable the actuator points in order to know the info , health of the project the dependency which you need to add is
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId></dependency>

Resources