1

To enable CORS in a JHipster Spring Boot app I am uncommenting the settings in application.ym.

jhipster:
  clientApp:
    name: 'modelDfApp'
  # By default CORS is disabled. Uncomment to enable.
    cors:
      allowed-origins: "*"
  #   allowed-methods: "*"
  #   allowed-headers: "*"
  #   exposed-headers: "Authorization,Link,X-Total-Count,X-${jhipster.clientApp.name}-alert,X-${jhipster.clientApp.name}-error,X-${jhipster.clientApp.name}-params"
  #   allow-credentials: true
  #   max-age: 1800

Note: Leaving most lines commented out here to shorted error message.

Intellij does not complain and maven compiles into Docker container no problem. But starting the container gives

2023-06-28 13:54:19 2023-06-28T12:54:19.799Z  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:
 org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'undertowServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedUndertow.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webConfigurer' defined in file [/app/classes/uk/modeldrivers/modeldf/config/WebConfigurer.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'jhipster-tech.jhipster.config.JHipsterProperties': Could not bind properties to 'JHipsterProperties' : prefix=jhipster, ignoreInvalidFields=false, ignoreUnknownFields=false; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'jhipster' to tech.jhipster.config.JHipsterProperties 
2023-06-28 13:54:19 2023-06-28T12:54:19.899Z ERROR 1 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : __***************************_APPLICATION FAILED TO START_***************************__Description:__Binding to target [Bindable@6f930e0 type = tech.jhipster.config.JHipsterProperties, value = 'provided', annotations = array<Annotation>
[@org.springframework.boot.context.properties.ConfigurationProperties(ignoreInvalidFields=false, ignoreUnknownFields=false, prefix="jhipster", value="jhipster")]] failed:__    
Property: jhipster.clientapp.cors.allowed-origins_    Value: "*"_    Origin: class path resource [config/application.yml] - 193:24_    
Reason: The elements [jhipster.clientapp.cors.allowed-origins] were left unbound.__Action:__Update your application's configuration_

Any suggestions gratefully received. Clues as to how you would debug this also very welcome.

3
  • What version of JHipster are you using? Jun 28 at 13:57
  • the latest 7.9.3 Matt. But I just found the answer and will post it now.
    – Harper2021
    Jun 28 at 14:20
  • I'm glad you figured it out! Jun 28 at 16:26

1 Answer 1

1

Ok, so I made the cors entry the same level as clientApp and it runs.

Looks like cors is a child of jhipster, not clientApp!

So

jhipster:
  clientApp:
    name: 'XXX'
  # By default CORS is disabled. Uncomment to enable.
  cors:
    allowed-origins: 'http://localhost:8080,http://localhost:9000'

not

jhipster:
  clientApp:
    name: 'XXX'
    # By default CORS is disabled. Uncomment to enable.
    cors:
      allowed-origins: 'http://localhost:8080,http://localhost:9000'
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jun 30 at 4:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.