JHipster with Okta Application Failed to Start due to UnsatisfiedDependencyException - jhipster

Getting the following error when starting JHipster Gateway application after adding OKTA configuration:
$ cd saathratrigateway
$ ./mvnw
...
2020-11-13 22:31:16.278 WARN 80043 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'authorizationHeaderUtil' defined in file [/Users/amar/workspace/saathratri-app-holder/saathratrigateway/target/classes/com/saathratri/security/oauth2/AuthorizationHeaderUtil.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.security.oauth2.client.OAuth2AuthorizedClientService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2020-11-13 22:31:16.280 DEBUG 80043 --- [ restartedMain] c.e.c.E.saathratri.domain.Authority : Close successful.
2020-11-13 22:31:16.281 DEBUG 80043 --- [ restartedMain] c.e.c.E.saathratri.domain.User : Close successful.
2020-11-13 22:31:16.281 DEBUG 80043 --- [ restartedMain] c.e.c.E.s.domain.User.authorities : Close successful.
2020-11-13 22:31:16.282 DEBUG 80043 --- [ restartedMain] c.ehcache.core.Ehcache-usersByEmail : Close successful.
2020-11-13 22:31:16.282 DEBUG 80043 --- [ restartedMain] c.ehcache.core.Ehcache-usersByLogin : Close successful.
2020-11-13 22:31:16.479 ERROR 80043 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.saathratri.security.oauth2.AuthorizationHeaderUtil required a bean of type 'org.springframework.security.oauth2.client.OAuth2AuthorizedClientService' that could not be found.
The following candidates were found but could not be injected:
- Bean method 'authorizedClientService' in 'OAuth2WebSecurityConfiguration' not loaded because #ConditionalOnBean (types: org.springframework.security.oauth2.client.registration.ClientRegistrationRepository; SearchStrategy: all) did not find any beans of type org.springframework.security.oauth2.client.registration.ClientRegistrationRepository
Action:
Consider revisiting the entries above or defining a bean of type 'org.springframework.security.oauth2.client.OAuth2AuthorizedClientService' in your configuration.
Any advise would be appreciated greatly.

Okay - figured it out. I had to create ~/.okta.env and then run source ~/.okta.env. See below....
$ vi ~/.okta.env
---
export SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI="https://dev-XXXXXXX.okta.com/oauth2/default"
export SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID="XXXXXXXXXXXXXXXXXXXX"
export SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET="XXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
export OKTA_OAUTH2_ISSUER="https://dev-XXXXXXX.okta.com/oauth2/default"
export OKTA_OAUTH2_CLIENT_ID_WEB="XXXXXXXXXXXXXXXXXXXX"
export OKTA_OAUTH2_CLIENT_SECRET_WEB="XXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
---
$ source ~/.okta.env
$ cd saathratrigateway
$ ./mvnw
I was following instructions from https://developer.okta.com/blog/2018/03/01/develop-microservices-jhipster-oauth.
Thank you Matt Raible!
Happy Diwali.

Related

o.s.boot.SpringApplication: Application run failed

I get this error after creating entity. Here is my log:
2021-01-12 11:56:39.828 DEBUG 9424 --- [ restartedMain] c.e.c.E.domain.User.authorities : Close successful.
2021-01-12 11:56:39.875 ERROR 9424 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: jdk11.domain.Libro.scritto in jdk11.domain.Scritto.libros
Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: jdk11.domain.Libro.scritto in jdk11.domain.Scritto.libros
How can i solve? I have already checked the entity names.

JHipster Registry - Exception on startup

Starting up JHipster Registry throws an exception and it seems to be some sort of nast catch-22 that I cannot resolve.
I imagine that the registry should not register itself, not try to pull its own configuration from the registry (rather that should come from its own environment). To this end, it comes pre-configured like this...
application.yml:
eureka:
client:
fetch-registry: false
register-with-eureka: false
However, the 'peer' configurations both come with both those values as 'true', and if you turn on the 'uaa' configuration, you turn on eureka.client.fetchRegistry=true.
Now, turning off the 'uaa' profile turns off the exception. Turning it on (because I need it), throws the exception.
2020-05-09 03:30:07.759 INFO 7 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2020-05-09 03:30:07.814 INFO 7 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2020-05-09 03:30:07.814 INFO 7 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2020-05-09 03:30:07.815 INFO 7 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2020-05-09 03:30:07.815 INFO 7 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2020-05-09 03:30:07.816 INFO 7 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2020-05-09 03:30:07.817 INFO 7 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2020-05-09 03:30:07.818 INFO 7 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2020-05-09 03:30:08.016 ERROR 7 --- [ main] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://admin:admin#registry.lo
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused)
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
Is there a way out of this?

jhipster cannot run on docker and local computer

I followed all the steps here: https://www.jhipster.tech/installation/
for the local configuration, the jhipster was successfully built but didn't run on port 8080. This is the error:
2020-05-06 08:11:56.212 WARN 521 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration$WebMvcServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthContributorRegistry]: Factory method 'healthContributorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'JHipsterHealthIndicatorConfiguration' defined in file [/home/jhipster/app/target/classes/com/kschain/app/config/metrics/JHipsterHealthIndicatorConfiguration.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraConfiguration': Invocation of init method failed; nested exception is com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/127.0.0.1:9042 (com.datastax.driver.core.exceptions.TransportException: [localhost/127.0.0.1:9042] Cannot connect))
2020-05-06 08:11:58.253 ERROR 521 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed
and this is what I got after all the steps are done
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 06:27 min
[INFO] Finished at: 2020-05-06T08:11:58Z
[INFO] ------------------------------------------------------------------------
2. The same problem occurred with the docker image
`2020-05-06 08:16:58.253 ERROR 521 --- [ restartedMain]
o.s.boot.SpringApplication: Application run failed`
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 06:27 min
[INFO] Finished at: 2020-05-06T08:18:58Z
[INFO] ------------------------------------------------------------------------
root#e8220a295cf8:/home/jhipster/app#
what's wrong?
The explanation is in the logs:
Error creating bean with name 'cassandraConfiguration': Invocation of init method failed; nested exception is com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: localhost/127.0.0.1:9042
You probably forgot to start Cassandra as explained in your project's generated README.md:
docker-compose -f src/main/docker/cassandra.yml up -d

Jhipster Gatway app logs show "Config Server: Not found or not setup for this application"

This issue should have been fixed long back as per this
Github ticket
Why Am i still seeing this in logs.
Config Server: Not found or not setup for this application
2017-10-30 15:03:53.740 INFO 24700 --- [ main] foo.bar.id.gateway.GatewayApp :
----------------------------------------------------------
Application 'Gateway' is running! Access URLs:
Local: http://localhost:8180
External: http://ipadddress:8180
Profile(s): [swagger, dev]
----------------------------------------------------------
2017-10-30 15:03:53.740 INFO 24700 --- [ main] foo.bar.id.gateway.GatewayApp :
----------------------------------------------------------
Config Server: Not found or not setup for this application
----------------------------------------------------------
2017-10-30 15:03:55.310 INFO 24700 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_AppGATEWAY/Gateway:2c4703cd1cbf3617def055e786113743: registering service...
2017-10-30 15:03:55.328 INFO 24700 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_AppGATEWAY/Gateway:2c4703cd1cbf3617def055e786113743 - registration status: 204
2017-10-30 15:08:20.870 INFO 24700 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
[1]: https://github.com/jhipster/generator-jhipster/issues/3166
If you expect that the config server may occasionally be unavailable when your application starts, you can make it keep trying after a failure. First, you need to set spring.cloud.config.fail-fast=true. Then you need to add spring-retry and spring-boot-starter-aop to your classpath. The default behavior is to retry six times with an initial backoff interval of 1000ms and an exponential multiplier of 1.1 for subsequent backoffs. You can configure these properties (and others) by setting the spring.cloud.config.retry.* configuration properties.
Docs:
https://cloud.spring.io/spring-cloud-config/reference/html/#config-client-retry
You need to set the following properties in your GitHub configuration repo.
configserver:
name: JHipster Registry config server
status: Connected to the JHipster Registry config server, using https://github.com/jhipster/jhipster-registry-sample-config !

Trouble using Spring Config Server in jhipster-registry

I created a microservice architecture using JHipster. I am using the jhipster-registry v2.8.0. I renamed the 'dev' profile to 'devdmi' because I will have many 'dev' profiles. It is working OK using the "dev,native" profiles for the jhipster-registry and each microservice including it's application-devdmi.yml / boostrap-devdmi.yml files.
I tried to convert this configuration over to using a Git repo. I built my Git repo with .yml files, but I'm not exactly sure of the configuration to use. At the moment I've got:
MyConfig/app1/MyApp1-devdmi.yml
MyConfig/app2/MyApp2-devdmi.yml
I also tried using:
MyConfig/MyApp1-devdmi.yml
MyConfig/MyApp2-devdmi.yml
In MyApp1, I renamed src/main/resources/config/application-devdmi.yml to application-devdmi.yml.bak hoping it would pick up the config from the jhipster-registry acting as a Spring Cloud Config Server.
In MyApp1, I have a bootstrap-devdmi.yml with:
spring:
application:
name: my-app-1
cloud:
config:
fail-fast: true
uri: http://admin:${jhipster.registry.password}#my.host.com:8761/config
name: MyApp1
profile: devdmi
label: master
The jhipster-registry starts up and shows it is connected to the Git repo by looking at the Configuration webpage.
MyApps1 doesn't start and throws an error about Liquibase not knowing which database to connect to:
2017-05-23 13:09:52.669 WARN 60704 --- [ main] o.s.boot.SpringApplication : Error handling failed (Error creating bean with name 'delegatingApplicationListener' defined in class path resource [org/springframework/security/config/annotation /web/configuration/WebSecurityConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor' defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor]: Factory method 'transactionAdvisor' threw exception; nested exception is java.lang.NullPointerException)
2017-05-23 13:09:52.683 ERROR 60704 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Cannot determine embedded database driver class for database type NONE
Any ideas?

Resources