Externalizing properties for Spring Boot - eclipse

I know there are quite a few threads on this, but none have solved my issue yet. I have a Spring Boot app that was running in Eclipse and I externalized the parameters in order to deploy to an external Tomcat and keep the properties out of the war. I moved my application.properties out of src/main/resources and into APP_ROOT/config. In catalina.sh, I added this:
JAVA_OPTS="-Dspring.profiles.active=local -Dspring.config.location=$CATALINA_BASE/conf/"
The external build is working fine; however, now it is not starting in Eclipse any longer. I replicated what I did in Tomcat by adding spring.config.location and spring.profiles.active to the VM arguments in the Launch Configuration.
During bootstrapping, it registers an Oracle driver (not the same version I specify in my properties file) and then stops. If I add:
#EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
to my config class so that driver isn't auto-registered, then I get:
No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate]
The odd part is that I tried putting my application.properties back in src/main/resources and removing the VM arguments and I'm getting the same behaviors. This is what I am seeing on startup without excluding the DataSourceAutoConfiguration. Any ideas?
2016-09-30 11:44:59.661 INFO 5150 --- [ main] org.usp.mct.MctApplication : Starting MctApplication on cici-mac.local with PID 5150 (/Users/cici/Documents/workspace-sts-3.7.3.RELEASE/mct.usp.org/target/classes started by cici in /Users/cici/Documents/workspace-sts-3.7.3.RELEASE/mct.usp.org)
2016-09-30 11:44:59.663 INFO 5150 --- [ main] org.usp.mct.MctApplication : The following profiles are active: local
2016-09-30 11:44:59.713 INFO 5150 --- [ main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#550ee7e5: startup date [Fri Sep 30 11:44:59 EDT 2016]; root of context hierarchy
2016-09-30 11:45:01.005 INFO 5150 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-09-30 11:45:01.019 INFO 5150 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-09-30 11:45:01.088 INFO 5150 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.9.Final}
2016-09-30 11:45:01.089 INFO 5150 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-09-30 11:45:01.091 INFO 5150 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-09-30 11:45:01.127 INFO 5150 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2016-09-30 11:45:01.598 INFO 5150 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.Oracle12cDialect
2016-09-30 11:45:01.749 INFO 5150 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [byte[]] overrides previous : org.hibernate.type.BinaryType#70972170
2016-09-30 11:45:01.749 INFO 5150 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [[B] overrides previous : org.hibernate.type.BinaryType#70972170
2016-09-30 11:45:01.750 INFO 5150 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [Byte[]] overrides previous : org.hibernate.type.WrapperBinaryType#69fe0ed4
2016-09-30 11:45:01.750 INFO 5150 --- [ main] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [[Ljava.lang.Byte;] overrides previous : org.hibernate.type.WrapperBinaryType#69fe0ed4
2016-09-30 11:45:02.181 INFO 5150 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2016-09-30 11:45:02.984 INFO 5150 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-09-30 11:45:02.992 INFO 5150 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
2016-09-30 11:45:03.059 INFO 5150 --- [ main] org.usp.mct.MctApplication : Started MctApplication in 3.796 seconds (JVM running for 4.181)
2016-09-30 11:45:03.060 INFO 5150 --- [ Thread-3] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#550ee7e5: startup date [Fri Sep 30 11:44:59 EDT 2016]; root of context hierarchy
2016-09-30 11:45:03.061 INFO 5150 --- [ Thread-3] o.s.c.support.DefaultLifecycleProcessor : Stopping beans in phase 0
2016-09-30 11:45:03.063 INFO 5150 --- [ Thread-3] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown

In this case, I blew away my repo and then re-cloned. Still have to get it working with external parameters instead of src/main/resources/application.properties, but at least I am back to square one.

Related

Getting exception when running Okta Spring Security & Okta-Hosted Login Page example

I followed the steps in this sample code: https://github.com/okta/samples-java-spring/tree/master/okta-hosted-login
When I run the example using the command:
mvn -Dokta.oauth2.issuer=https://{yourOktaDomain}/oauth2/default \ -Dokta.oauth2.clientId={clientId} \ -Dokta.oauth2.clientSecret={clientSecret}
I get the following exception:
`2023-02-06 11:08:41.717 INFO 17288 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2023-02-06 11:08:41.725 INFO 17288 --- [ main] c.o.s.e.CodeFlowExampleApplication : Started CodeFlowExampleApplication in 2.881 seconds (JVM running for 5.358)
2023-02-06 11:08:53.299 INFO 17288 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-02-06 11:08:53.299 INFO 17288 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2023-02-06 11:08:53.301 INFO 17288 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 0 ms
2023-02-06 11:08:53.558 ERROR 17288 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.thymeleaf.context.IWebContext.getExchange()Lorg/thymeleaf/web/IWebExchange;] with root cause
java.lang.NoSuchMethodError: org.thymeleaf.context.IWebContext.getExchange()Lorg/thymeleaf/web/IWebExchange;
at org.thymeleaf.extras.springsecurity5.util.Spring5VersionSpecificUtility.isWebMvcContext(Spring5VersionSpecificUtility.java:80) ~[thymeleaf-extras-springsecurity5-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.thymeleaf.extras.springsecurity5.util.SpringVersionSpecificUtils.isWebMvcContext(SpringVersionSpecificUtils.java:118) ~[thymeleaf-extras-springsecurity5-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.thymeleaf.extras.springsecurity5.util.SpringSecurityContextUtils.getAuthenticationObject(SpringSecurityContextUtils.java:127) ~[thymeleaf-extras-springsecurity5-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.thymeleaf.extras.springsecurity5.auth.AuthUtils.getAuthenticationObject(AuthUtils.java:102) ~[thymeleaf-extras-springsecurity5-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.thymeleaf.extras.springsecurity5.dialect.expression.SpringSecurityExpressionObjectFactory.buildObject(SpringSecurityExpressionObjectFactory.java:91) ~[thymeleaf-extras-springsecurity5-3.1.1.RELEASE.jar:3.1.1.RELEASE]
...`
I also tried running this sample from my Intellij IDEA IDE and when I open it I get the following error:
'parent.relativePath' of POM com.example.okta:okta-spring-boot-oauth-code-flow-example:0.0.1-SNAPSHOT (C:\Users\fteran\repos\demos\okta-github\samples-java-spring\okta-hosted-login\pom.xml) points at com.okta.examples:aggregator instead of org.springframework.boot:spring-boot-starter-parent, please verify your project structure
I was kind of expecting the sample code to work if I was very careful to follow the instructions, which I think I did, at this point I am not sure if this is an issue on my local or if there is an issue with the sample code itself.
Try this example: https://github.com/okta-samples/okta-spring-boot-sample/
It's more up-to-date.

Failing to start up HazelCast on AWS ECS

I'm trying to start up Hazelcast on AWS ECS. I have gone through the tutorial and have enabled all the permissions on the task role i.e decribeTasks, lisTasks etc. I have have a very simple configuration file
hazelcast:
cluster-name: hs-dcom-hazelcast
network:
join:
multicast:
enabled: false
aws:
enabled: true
interfaces:
enabled: true
interfaces:
- 10.106.*.*
However when the container tries to start it throws the following error
2023-01-23T14:47:16.975Z INFO 835 --- [ main] com.hazelcast.instance.impl.Node : [10.106.139.69]:5701 [hs-dcom-hazelcast] [5.0-BETA-1] Shutting down node engine...
7467 2023-01-23T14:47:17.004Z INFO 835 --- [ main] c.hazelcast.instance.impl.NodeExtension : [10.106.139.69]:5701 [hs-dcom-hazelcast] [5.0-BETA-1] Destroying node NodeExtension.
7468 2023-01-23T14:47:17.004Z INFO 835 --- [ main] com.hazelcast.instance.impl.Node : [10.106.139.69]:5701 [hs-dcom-hazelcast] [5.0-BETA-1] Hazelcast Shutdown is completed in 35 ms.
! 7469 2023-01-23T14:47:17.006Z WARN 835 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hazelcastInstance' defined in class path resource [org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration$HazelcastServerConfigFileConfiguration.class]: Failed to instantiate [com.hazelcast.core.HazelcastInstance]: Factory method 'hazelcastInstance' threw exception with message: Failure executing: POST at: https://ecs.eu-west-1.amazonaws.com. Message: {"__type":"InvalidParameterException","message":"Identifier is for 570169269855. Your accountId is 531465454359"}. HTTP Error Code: 400
7470 2023-01-23T14:47:17.021Z INFO 835 --- [ main] .s.b.a.l.ConditionEvaluationReportLogger :
7471
7472 Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
7473 2023-01-23T14:47:17.052Z ERROR 835 --- [ main] o.s.boot.SpringApplication : Application run failed
7474
7475 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hazelcastInstance' defined in class path resource [org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration$HazelcastServerConfigFileConfiguration.class]: Failed to instantiate [com.hazelcast.core.HazelcastInstance]: Factory method 'hazelcastInstance' threw exception with message: Failure executing: POST at: https://ecs.eu-west-1.amazonaws.com. Message: {"__type":"InvalidParameterException","message":"Identifier is for 570169269855. Your accountId is 531465454359"}. HTTP Error Code: 400
7476 at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657) ~[spring-beans-6.0.3.jar:6.0.3]
7477 at
I have tried looking on the forum, however can't seem to find anyone that has had this issue before.

Spring Cloud Data Flow Kinises Example Consumer Failing

I have cloned the SCDF Kinesis Example: https://github.com/spring-cloud/spring-cloud-dataflow-samples/tree/master/dataflow-website/recipes/kinesisdemo and running the same. The kinesis Producer is running and publishing the events to kinesis. However, the Kinesis Consumer Spring Boot is failed to start due to the below ERRORS. Please let me know if anybody faced this issue and how to solve this?
2020-06-25 17:55:07.374 WARN 2448 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kinesisCheckpointStore' defined in org.springframework.cloud.stream.binder.kinesis.config.KinesisBinderConfiguration: Invocation of init method failed; nested exception is com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: User: arn:aws:sts::123456789:assumed-role/xyz-dev-yyyzz-support-role/user#company.com is not authorized to perform: dynamodb:DescribeTable on resource: arn:aws:dynamodb:us-east-2:123456789:table/SpringIntegrationMetadataStore (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: AccessDeniedException; Request ID: P0FF48TJVDUO29L9ULKQN89CKBVV4KQNSO5AEMVJF66Q9ASUAAJG)
2020-06-25 17:55:07.378 INFO 2448 --- [ main] o.s.s.c.ThreadPoolTaskScheduler : Shutting down ExecutorService 'taskScheduler'
2020-06-25 17:55:07.379 INFO 2448 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Summary on shutdown: nullChannel
2020-06-25 17:55:07.379 INFO 2448 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Summary on shutdown: input
2020-06-25 17:55:07.379 INFO 2448 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Summary on shutdown: errorChannel
2020-06-25 17:55:07.379 INFO 2448 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Summary on shutdown: _org.springframework.integration.errorLogger.handler
2020-06-25 17:55:07.379 INFO 2448 --- [ main] o.s.i.monitor.IntegrationMBeanExporter : Summary on shutdown: org.springframework.cloud.stream.binding.StreamListenerMessageHandler#3e03046d
2020-06-25 17:55:07.390 INFO 2448 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-06-25 17:55:07.391 ERROR 2448 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'inputBindingLifecycle'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kinesisCheckpointStore' defined in org.springframework.cloud.stream.binder.kinesis.config.KinesisBinderConfiguration: Invocation of init method failed; nested exception is com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: User: arn:aws:sts::123456789:assumed-role/xyz-dev-yyyzz-support-role/user#company.com is not authorized to perform: dynamodb:DescribeTable on resource: arn:aws:dynamodb:us-east-2:123456789:table/SpringIntegrationMetadataStore (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: AccessDeniedException; Request ID: P0FF48TJVDUO29L9ULKQN89CKBVV4KQNSO5AEMVJF66Q9ASUAAJG)
Check your configuration on credentials provided for the app as the error clearly says it failed due to "Status Code: 400; Error Code: AccessDeniedException"

Spring Batch multiple jobs at once started?

In my spring batch i see following logs.
INFO 5572 --- [ scheduling-1] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=sample]] launched with the following parameters: [{JobID=x}]
INFO 5572 --- [ main] o.s.b.c.l.support.SimpleJobLauncher : Job: [FlowJob: [name=sample]] launched with the following parameters: [{run.id=1, JobID=y}]
INFO 5572 --- [ scheduling-1] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
INFO 5572 --- [ main] o.s.batch.core.job.SimpleStepHandler : Executing step: [step1]
Is this same log lines repeated by two threads or two jobs started at once ?
According to your logs, two different job instances are executed by two different threads: scheduling-1 and main.

Swagger can't start in jhipster when using Eclipse

I'm working on application with jhipster. It was good so far however today I have an issue that I can't resolve.
When I use Eclipse I can't start application. I suppose that it is caused of Swagger can't start.
It looks like that:
The Class-Path manifest attribute in C:\Users\twloszki\.m2\repository\org\liquibase\liquibase-core\3.5.5\liquibase-core-3.5.5.jar referenced one or more files that do not exist: file:/C:/Users/twloszki/.m2/repository/org/liquibase/liquibase-core/3.5.5/lib/snakeyaml-1.13.jar
13:22:12.567 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Included patterns for restart : []
13:22:12.567 [main] DEBUG org.springframework.boot.devtools.settings.DevToolsSettings - Excluded patterns for restart : [/spring-boot-starter/target/classes/, /spring-boot-autoconfigure/target/classes/, /spring-boot-starter-[\w-]+/, /spring-boot/target/classes/, /spring-boot-actuator/target/classes/, /spring-boot-devtools/target/classes/]
13:22:12.567 [main] DEBUG org.springframework.boot.devtools.restart.ChangeableUrls - Matching URLs for reloading : [file:/C:/GSMR/ICOMS-web/target/classes/]
██╗ ██╗ ██╗ ████████╗ ███████╗ ██████╗ ████████╗ ████████╗ ███████╗
██║ ██║ ██║ ╚══██╔══╝ ██╔═══██╗ ██╔════╝ ╚══██╔══╝ ██╔═════╝ ██╔═══██╗
██║ ████████║ ██║ ███████╔╝ ╚█████╗ ██║ ██████╗ ███████╔╝
██╗ ██║ ██╔═══██║ ██║ ██╔════╝ ╚═══██╗ ██║ ██╔═══╝ ██╔══██║
╚██████╔╝ ██║ ██║ ████████╗ ██║ ██████╔╝ ██║ ████████╗ ██║ ╚██╗
╚═════╝ ╚═╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══════╝ ╚═╝ ╚═╝
:: JHipster 🤓 :: Running Spring Boot 1.5.14.RELEASE ::
:: http://www.jhipster.tech ::
2019-01-21 13:22:13.580 INFO 2492 --- [ restartedMain] com.App : Starting App on PC
2019-01-21 13:22:13.580 DEBUG 2492 --- [ restartedMain] com.App : Running with Spring Boot v1.5.14.RELEASE, Spring v4.3.18.RELEASE
2019-01-21 13:22:13.580 INFO 2492 --- [ restartedMain] com.App : The following profiles are active: swagger,dev
2019-01-21 13:22:13.861 DEBUG 2492 --- [kground-preinit] org.jboss.logging : Logging Provider: org.jboss.logging.Slf4jLoggerProvider found via system property
2019-01-21 13:22:16.660 DEBUG 2492 --- [ restartedMain] p.w.g.config.AsyncConfiguration : Creating Async Task Executor
2019-01-21 13:22:17.347 DEBUG 2492 --- [ restartedMain] p.w.g.config.MetricsConfiguration : Registering JVM gauges
2019-01-21 13:22:17.472 DEBUG 2492 --- [ restartedMain] p.w.g.config.MetricsConfiguration : Monitoring the datasource
2019-01-21 13:22:17.472 DEBUG 2492 --- [ restartedMain] p.w.g.config.MetricsConfiguration : Initializing Metrics JMX reporting
2019-01-21 13:22:18.421 DEBUG 2492 --- [ restartedMain] com.config.WebConfigurer : Registering CORS filter
2019-01-21 13:22:18.625 INFO 2492 --- [ restartedMain] com.config.WebConfigurer : Web application configuration, using profiles: swagger
2019-01-21 13:22:18.625 DEBUG 2492 --- [ restartedMain] com.config.WebConfigurer : Initializing Metrics registries
2019-01-21 13:22:18.625 DEBUG 2492 --- [ restartedMain] com.config.WebConfigurer : Registering Metrics Filter
2019-01-21 13:22:18.625 DEBUG 2492 --- [ restartedMain] com.config.WebConfigurer : Registering Metrics Servlet
2019-01-21 13:22:18.625 INFO 2492 --- [ restartedMain] com.config.WebConfigurer : Web application fully configured
2019-01-21 13:22:18.922 DEBUG 2492 --- [ restartedMain] p.w.g.config.DatabaseConfiguration : Configuring Liquibase
2019-01-21 13:22:18.937 WARN 2492 --- [port-Executor-1] i.g.j.c.liquibase.AsyncSpringLiquibase : Starting Liquibase asynchronously, your database might not be ready at startup!
2019-01-21 13:22:23.527 DEBUG 2492 --- [ restartedMain] c.ehcache.core.Ehcache-usersByLogin : Initialize successful.
2019-01-21 13:22:23.527 DEBUG 2492 --- [ restartedMain] c.ehcache.core.Ehcache-usersByEmail : Initialize successful.
2019-01-21 13:22:23.543 DEBUG 2492 --- [ restartedMain] c.e.c.E.w.g.domain.DictionaryValue : Initialize successful.
2019-01-21 13:22:23.543 DEBUG 2492 --- [ restartedMain] c.e.c.E.w.g.domain.DictionaryType : Initialize successful.
2019-01-21 13:22:23.543 DEBUG 2492 --- [ restartedMain] c.e.c.E.domain.Line : Initialize successful.
2019-01-21 13:22:23.543 DEBUG 2492 --- [ restartedMain] c.e.c.E.domain.Section : Initialize successful.
2019-01-21 13:22:23.583 DEBUG 2492 --- [ restartedMain] c.e.c.E.domain.WorkCost : Initialize successful.
2019-01-21 13:22:23.585 DEBUG 2492 --- [ restartedMain] c.e.c.E.domain.WorkAttachment : Initialize successful.
The next step should be:
2019-01-21 13:07:24.089 DEBUG 10764 --- [ restartedMain] i.g.j.c.apidoc.SwaggerConfiguration : Starting Swagger
2019-01-21 13:07:24.096 DEBUG 10764 --- [ restartedMain] i.g.j.c.apidoc.SwaggerConfiguration : Started Swagger in 6 ms
Somehow swagger can't start and nothing happen.
Edit: The funny thing is that I can run my application with mvnw command in cmd.
I found solution. I tried to turn on my application in debug mode however when I just run it everything was okay. I removed all breakpoints that I had in code and that helped me.