This question already has answers here:
Configure active profile in SpringBoot via Maven
(9 answers)
Closed 2 years ago.
I have vault integrated with my spring-boot application and I am facing I guess a very weird issue. When I run my application using
java -Dspring.profiles.active=dev -jar BatchProcessing-0.0.1-SNAPSHOT.jar
runs successfully but when I use
mvn spring-boot:run
I get the below exception.
Can anyone please give me a brief description of what can be the difference between the two? Thank You!
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'vaultTemplate' defined in class path resource [org/springframework/cloud/vault/config/VaultBootst
rapConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.vault.co
re.VaultTemplate]: Factory method 'vaultTemplate' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'vaultSession
Manager' defined in class path resource [org/springframework/cloud/vault/config/VaultBootstrapConfiguration.class]: Unsatisfied dependency expressed through method 'vaultSessionManager' parameter
0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'clientAuthentication' defined in class path resource [org/springframework/cloud/vault
/config/VaultBootstrapConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.sprin
gframework.vault.authentication.ClientAuthentication]: Factory method 'clientAuthentication' threw exception; nested exception is java.lang.IllegalArgumentException: Token (spring.cloud.vault.toke
n) must not be empty
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:656) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:484) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.5.RELEASE.jar
:5.2.5.RELEASE]
If you want to activate a profile when running with the Maven Plugin you must pass the profile like this:
mvn spring-boot:run -Dspring-boot.run.profiles=dev
Related
I am developing my application on Java version 1.8 and since my repository is on bitbucket, it is picking up the default configuration of Java 11.
Everything is working fine but when I am writing Integration Tests using Junit Mockito framework I am getting exception on bitbucket while executing the pipeline. Locally all tests are working fine.
Bitbucket by default is picking the latest version on sonar plugin which is 3.9 and because of that I am getting this exception
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar (default-cli) on project xyz: Execution default-cli of goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar failed: An API incompatibility was encountered while executing org.sonarsource.scanner.maven:sonar-maven-plugin:3.9.1.2184:sonar: java.lang.UnsupportedClassVersionError: org/sonar/batch/bootstrapper/EnvironmentInformation has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
I have tried following changes but nothing happened
1) Changed image: maven:3.6.3-jdk-11 To image: maven:3.6.3-jdk-8 in bitbucket-pipeline.yml file.
2) Added jacoco 0.7.9 version (Java 8 compatible) in pom file
3) Added sonar-maven-plugin version 3.6 (tried to downgrade it to be compatible with Java 8) in pom file
Can someone guide what is missing and what can be the issue. Also if I want to change the default bitucket docker image configuration how can I do that?
My bitbucket-pipeline.yml file
image: maven:3.6.3-jdk-11 #image: maven:3.6.3-jdk-8
clone
....
definitions
caches
sonar: ....
steps
...
...
script:
cd impl
mvn -B org.jacoco:jacoco-maven-plugin:prepare-agent verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
My Integration Test File
#SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
#AutoConfigureMockMvc
#ActiveProfiles("test")
#RunWith(SpringRunner.class)
public class CountryControllerTest{
#Autowired public MockMvc mockMvc;
#Test
public void getCountryListTest() throws Exception {
mockMvc
.perform(MockMvcRequestBuilders.get("/api/countries"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("$.data.length()").value(2))
.andExpect(jsonPath("$.data[0].name").value("USA"))
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
}
}
The Error is only occurring on bitbucket pipeline and not in local development
[ERROR] getCountryListTest(com.xyz.controller.CountryControllerTest) Time elapsed: 0.001 s <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'MyTokenFilter': Unsatisfied dependency expressed through field 'myRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRepository': Cannot create inner bean '(inner bean)#7675d305' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#12345': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is 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 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myRepository': Cannot create inner bean '(inner bean)#12345' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#12345': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is 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 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#12345': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is 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 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: 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 javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Caused by: org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
Caused by: java.lang.reflect.InvocationTargetException
Caused by: java.lang.NullPointerException
Try Java SE 17. Java SE 8 is slowly being discontinued.
Or else try using GitHub or GitLab. that should do the trick.
there is also a free app called ci circle in Github.
it is very easy once you install it.it's free for the bonus.
it can build your apps automatically every time you commit.
When executing or debugging Intellij Idea on a mac, errors in stack trace are concatenated into one line. How do I fix the line delimiter settings?
example output:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-09-09 06:17:55.961 ERROR 89612 ---[main] - [Trace-] o.s.boot.SpringApplication - Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'costOrchestrationServiceComponent' defined in file [/Users/git/mydir/build/classes/java/main/adjustment/component/CostOrchestrationServiceComponent.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'appCredentialsFromVault' defined in class path resource [com.whatever.adjustment/config/PromotionAppSecretsConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.whatever.adjustment.domain.AppCredentialsFromVault]: Factory method 'appCredentialsFromVault' threw exception; nested exception is com.whatever.vault.exception.VaultAccessException: [VAULT EXCEPTION] Error connecting to Vault. Could not log into Vault and retrieve auth token.u2028 at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769)u2028 at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218)u2028 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(Abstra
I am working on a spring boot application with latest Angular 7. I have created a build and generated war file.
I have configured a folder in this the structure is :
project-tool.war
config/application-prod.yml
config/application-dev.yml
config/application.yml
run.sh
run.bat
In run.sh/run.bat, these command written -> java -jar project-tool.war --spring.profiles.active=prod --spring.config.location=config\application-prod.yml
I have created Oracle database instance on AWS and put the configuration in application-prod.yml.
Then I have run this project using the war file on Windows OS, it works fine.
I have to run this war file on Amazon EC2 instance. So I have uploaded this folder on EC2 medium instance. As I run this, it throws an error :
2019-03-02 06:50:53.489 ERROR 3082 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'securityConfiguration': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService' defined in URL [jar:file:/home/ec2-user/theProject/project-tool.war!/WEB-INF/classes!/com/myProject/security/DomainUserDetailsService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userService': Unsatisfied dependency expressed through field 'auditLogService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'auditLogService' defined in URL [jar:file:/home/ec2-user/theProject/project-tool.war!/WEB-INF/classes!/com/myProject/service/AuditLogService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'auditLogRepository': Cannot create inner bean '(inner bean)#44dbafd9' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#44dbafd9': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: IO Error: The Network Adapter could not establish the connection
2019-03-02 06:50:53.551 WARN 3082 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [oracle.jdbc.driver.BlockSource.ThreadedCachingBlockSource.BlockReleaser] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
oracle.jdbc.driver.BlockSource$ThreadedCachingBlockSource$BlockReleaser.run(BlockSource.java:327)
2019-03-02 06:50:53.556 WARN 3082 --- [ main] ConfigServletWebServerApplicationContext : 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: Unable to start embedded Tomcat
I also have another instance and other project working (spring and angularJS) fine in a similar manner. But why this not working, is there any issue with the command or with angular?
How to work it on Amazon EC2?
Your problem here reading your error stack trace is the database connection. Pay attention to the core error message:
Failed to initialize pool: IO Error: The Network Adapter could not establish the connection
I don't know how the Oracle database is configured but probably you have a problem with database listener configuration or more simply whit the network communication between your EC2 and Oracle Database instance i can suggest to try to see on the security group and network configuration.
The problem is not Angular but the database link between your app and the database.
I have deployed cassandra 3.11 service in openshift (OpenShift Web Console )
Through port forwarding, I am to connect to cassandra service through my local
terminal.
oc port-forward cassandra-0 9042:9042
cqlsh -u cassandra -p cassandra
I want to access cassandra service through my springboot application.
For that I am using below property file.
spring.data.cassandra.contact-points=cassandra-0.cassandra-1:9042,cassandra-1.cassandra-1:9042,cassandra-2.cassandra-1:9042
#spring.data.cassandra.port=9042
spring.data.cassandra.username=cassandra
spring.data.cassandra.password=cassandra
spring.data.cassandra.cluster-name=cassandra
When I am trying to run springboot application through above property file I am getting below error
org.springframework.beans.factory.BeanCreationException. Message: 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 forg.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrad: 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 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthIndicatorRegistry' defined in class path resource [org/springframework/boot/actuate /autoconfigure/health/HealthIndicatorAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org. springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthIndicatorRegistry]: Factory method 'healthIndicatorRegistry' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.cassandra.CassandraHealthIndicatorAutoConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'cassandraTemplate' defined in class path resource [o rg/springframework/boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: Unsatisfied dependency expressed through method 'cassandraTemplate' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cassandraSession' defined in class path resource [org/springframework /boot/autoconfigure/data/cassandra/CassandraDataAutoConfiguration.class]: Invocation of init method failed; nested exception is com.datastax.driver.core.exceptions.AuthenticationException: Authentication error on host cassandra.b360—non—prod.svc/10.128.16.156:9042: Host cassandra.b360— non—prod.svc/10.128.16.156:9042 requires authentication, but no authenticator found in Cluster configuration 2019-02-12 00:59:50.026 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2019-02-12 00:59:50.141 WARN 1 --- [ main] o.a.c.loader.WebappClassLoaderBase : The web application [ROOT] appears to have started a thread named [cluster1— connection—reaper-0] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
Try localhost:9042.
oc port-forward can forward requests from local to remote pod. So, accessing localhost:9042 will forward to cassandra-0:9042
I'm trying to run the completed version of the Yummy Noodle Bar tutorials (REST + WebApp) locally, so that I can dig through the code a little bit on my 2*6hr bus rides this weekend.
http://spring.io/guides/tutorials/web/
http://spring.io/guides/tutorials/rest/
According to both guides, the finished code is available:
$ cd ../6/complete
$ ./gradlew tomcatRunWar
However, both versions do not run for me and give build errors.
Can anyone else manage to run these? Is there anything wrong with my Java version or Path?
2014-09-19 09:36:10 ERROR ContextLoader:319 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setObjectPostProcessor(org.springframework.security.config.annotation.ObjectPostProcessor); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectPostProcessor' defined in class org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration': Initialization of bean failed; nested exception is java.lang.IllegalStateException: org.springframework.core.NestedIOException: ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet: class path resource [com/yummynoodlebar/config/SecurityConfig.class]; nested exception is java.lang.IllegalArgumentException
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)