Can't manage run the completed Spring Yummy Noodle Bar tutorials - java

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)

Related

Bitbucket Jdk Version Mismatch Issue

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.

Intellij idea - there are no line breaks in stack trace

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

Java Command vs spring-boot:run command [duplicate]

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

Unable to run war file on Amazon EC2 instance

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.

How to debug ContextLoader - Context initialization failed and BeanCreationException

I see a number of posts on the various problems folks have with troubleshooting this problem:
ERROR context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException:
Is there a way to turn on debugging to isolate the problem?
Its complaining about "No such property: getOrg for class: groovy.lang.MetaClassImpl" but that's not directly one one of our classes, is there some way to get info that's relevant to our codebase?
In our case we had a Grails 1.2.1 app deployed and running just fine in Tomcat. We then stopped Tomcat to do a DB backup and then restarted the app. The same WAR with no environmental changes(i.e, no config file changes, etc.) now throws this error. We had observed this behavior intermittently previously as well, but restarting used to fix the prob.
In our development environment, the same app runs just fine with "grails prod run-app" as well as "grails prod run-war".
The stacktrace snippets:
2010-09-30 12:10:13,391 ERROR
context.ContextLoader - Context
initialization failed
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'messageSource': Initialization of
bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'transactionManager': Cannot resolve
reference to bean 'sessionFactory'
while setting bean property
'sessionFactory'; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'sessionFactory': Invocation of init
method failed; nested exception is
groovy.lang.MissingPropertyException:
No such property: getOrg for class:
groovy.lang.MetaClassImpl
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.doCreateBean(ReloadAwareAutowireCapableBeanFactory.java:129)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
<<<<<<<< snip >>>>>>>>>>>>>>>>>>>>>>
Caused by: groovy.lang.MissingPropertyException: No such property: getOrg for class: groovy.lang.MetaClassImpl
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:49)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:485)
at org.codehaus.groovy.grails.plugins.orm.hibernate.HibernatePluginSupport.handleLazyProxy(HibernatePluginSupport.groovy:413)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindProperty(GrailsDomainBinder.java:2108)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.createProperty(GrailsDomainBinder.java:1829)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.createClassProperties(GrailsDomainBinder.java:1565)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindJoinedSubClass(GrailsDomainBinder.java:1272)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindSubClass(GrailsDomainBinder.java:1219)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindSubClasses(GrailsDomainBinder.java:1186)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindRoot(GrailsDomainBinder.java:1160)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindClass(GrailsDomainBinder.java:1040)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration.secondPassCompile(GrailsAnnotationConfiguration.java:145)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
If you set logging level to DEBUG for packages org.springframework and org.codehaus.groovy then you will be able to get more details.
But in case of grails sometimes it helps just to stop tomcat, remove work and temp directories and start tomcat again.
I've gotten this in grails 1.3.4, and removing the tomcat work and temp directories ($CATALINA_BASE/temp, $CATALINA_BASE/work) does seem to fix the problem.

Categories

Resources