Spring Boot fails to bootRun - spring

I'm trying to create my first Spring Boot application using Gradle in osx. When I run the command gradle bootrun I get the following error:
Task :bootRun FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':bootRun'.
Process 'command '/Library/Java/JavaVirtualMachines/jdk-10.0.2.jdk/Contents/Home/bin/java'' finished with non-zero exit value 1.
My build.gradle-file looks like this(I'v added three dependencies, rest repositories, h2 and jpa):
buildscript {
ext {
springBootVersion = '2.0.4.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'io.simon'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
runtime('com.h2database:h2')
testCompile('org.springframework.boot:spring-boot-starter-test')
}
Any idea?
Thanks
Edit: More errorcodes
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-08-29 16:45:55.800 ERROR 51728 --- [ main] 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 java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:573) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1089) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:859) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
at io.navan.courses.CoursesApplication.main(CoursesApplication.java:10) [main/:na]
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
at org.hibernate.boot.spi.XmlMappingBinderAccess.<init>(XmlMappingBinderAccess.java:43) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
at org.hibernate.boot.MetadataSources.<init>(MetadataSources.java:87) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:209) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:164) ~[hibernate-core-5.2.17.Final.jar:5.2.17.Final]
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:51) ~[spring-orm-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1758) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1695) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]
... 16 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) ~[na:na]
... 27 common frames omitted

Related

Gradle multi module project java.lang.NoClassDeffFoundError

i have the following simple test-project-structure
|TestProject
|
|---project-a
| |---src
| |---main
| |---java
| |---package-name.ProjectA
| |---service
| | |---TestService.java
| |
| |---ProjectAServiceApplication.java
|
|---project-b
| |---src
| |---main
| |---java
| |---package-name.ProjectB
| |---enums
| |---Commodity.java
|
|---build.gradle
|---settings.gradle
The build.gradle looks like
import com.commercehub.gradle.plugin.avro.GenerateAvroJavaTask
import groovy.json.*
buildscript {
ext {
springCloudVersion = 'Greenwich.RELEASE'
springBootVersion = '2.1.2.RELEASE'
}
repositories {
mavenCentral()
jcenter()
maven {
url "http://packages.confluent.io/maven"
}
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://projectlombok.org/edge-releases' }
}
dependencies {
classpath "org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}"
classpath "com.commercehub.gradle.plugin:gradle-avro-plugin:0.14.2"
classpath "net.ltgt.gradle:gradle-apt-plugin:0.21"
}
}
plugins {
id "net.ltgt.apt" version "0.21" apply false
id "io.spring.dependency-management" version "1.0.8.RELEASE"
}
subprojects {
// Packer variables
ext {
packerVariablesFolder = "$buildDir/packer"
packerVariablesPath = "$packerVariablesFolder/$packerVariables"
packerTemplateFolder = "../config"
packerTemplatePath = "$packerTemplateFolder/$packerTemplate"
}
apply plugin: 'idea'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'java'
apply plugin: 'java-library'
apply plugin: 'org.springframework.boot'
group = 'de.SWS.PLM'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
repositories {
mavenCentral()
jcenter()
maven {
url "http://packages.confluent.io/maven"
}
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://projectlombok.org/edge-releases' }
}
springBoot {
buildInfo()
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
}
}
ext.convertProjectName = { ->
return project.name.split("(?<!(^|[A-Z]))(?=[A-Z])|(?<!^)(?=[A-Z][a-z])").join("-").toLowerCase()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-actuator'
compile group: 'log4j', name: 'log4j', version: '1.2.17'
compile 'org.apache.commons:commons-lang3:3.10'
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
task defineBuildVersion {
if (project.hasProperty("revision")) {
ext.imageVersion = version + "-${revision}"
} else {
ext.imageVersion = version + "-SNAPSHOT"
}
}
compileJava {
//raise heap
options.fork = 'true'
options.forkOptions.with {
memoryMaximumSize = '2048m'
}
}
task generatePackerFiles {
doLast {
mkdir "$packerVariablesFolder"
new File("$packerVariablesPath").text = JsonOutput.toJson([
jar_file: jar.archiveName,
logback_file: "logback-pfm.xml",
image_name: "$convertProjectName",
image_tag: "${defineBuildVersion.imageVersion}"
])
}
}
task buildDockerImage(type: Exec) {
dependsOn generatePackerFiles
commandLine 'packer', 'build', "-var-file=${packerVariablesPath}", "${packerTemplatePath}"
}
compileJava {
//raise heap
options.fork = 'true'
options.forkOptions.with {
memoryMaximumSize = '2048m'
}
}
task cleanIntellijDirs(type: Delete) {
delete 'out'
}
}
configure(subprojects.findAll { !['project-b'].contains(it.name)} ) {
dependencies {
implementation project(':project-b')
}
}
and the settings.gradle looks like
rootProject.name = 'TestProject'
include 'project-a'
include 'project-b'
If i run the gradlew task build for project-a gradle :project-a:build it builds the project correctly and generate a *.jar file.
If i execute the *.jar file i get the following output
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testService' defined in URL [jar:file:/C:/Users/sws-216/Documents/Projekte/pfm-project/TestProject/project-a/build/libs/project-a-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/de/SWS/PLM/ProjectA/service/TestService.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.SWS.PLM.ProjectA.service.TestService]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: de/SWS/PLM/Commodity
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1270) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1164) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~[spring-context-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.2.RELEASE.jar!/:2.1.2.RELEASE]
at de.SWS.PLM.ProjectA.ProjectAServiceApplication.main(ProjectAServiceApplication.java:10) ~[classes!/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48) ~[project-a-0.0.1-SNAPSHOT.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87) ~[project-a-0.0.1-SNAPSHOT.jar:na]
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50) ~[project-a-0.0.1-SNAPSHOT.jar:na]
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51) ~[project-a-0.0.1-SNAPSHOT.jar:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [de.SWS.PLM.ProjectA.service.TestService]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: de/SWS/PLM/Commodity
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:87) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1262) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
... 24 common frames omitted
Caused by: java.lang.NoClassDefFoundError: de/SWS/PLM/Commodity
at de.SWS.PLM.ProjectA.service.TestService.<init>(TestService.java:12) ~[classes!/:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:na]
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490) ~[na:na]
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172) ~[spring-beans-5.1.4.RELEASE.jar!/:5.1.4.RELEASE]
... 26 common frames omitted
Caused by: java.lang.ClassNotFoundException: de.SWS.PLM.Commodity
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589) ~[na:na]
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93) ~[project-a-0.0.1-SNAPSHOT.jar:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) ~[na:na]
... 32 common frames omitted
What i do wrong setting up the gradle multi modules project?
The issue is in the way you are packaging project-b. You are relying on it as both a library (because you are depending on it from project-a) and as a stand-alone executable jar. But you can't use the same jar file for both these use-cases.
When you apply the Spring Boot plugin, it will by default disable the normal jar task and instead produce a "fat" jar with all dependencies bundled up, but also arranged in a way that a normal Java program can no longer find classes in it. To re-enable the original jar task, and rename the fat jar as it has the same name, do this:
jar {
enabled = true
}
bootJar {
classifier = 'boot'
}
When you do this, you will get two jar files on build. One is for when you use it as a normal dependency, and the other is for executing it.
I assume the reason it works in IntelliJ without this is because you are either not delegating your tasks to Gradle, or you are running it through bootRun. Both approaches will not build and run the final executable jar, but rather just use the compiled classes in an exploded form.
Sometimes, a better design is to extract the classes which are common to both project-a and project-b into a shared utility project instead of bundling an entire application inside another application (and sometimes this is what you want of cause). But you will need to do the same configuration for this as the above if you apply the Spring Boot plugin on it, which you might do for the reaction to the dependency-management plugin.
You can find more information on this in the documentation for the documentation for the Spring Boot Gradle plugin under Packaging Executable and Normal Archives.
Ok, i do the following
add
jar {
enabled = true
}
bootJar {
classifier = 'boot'
}
to my project-a. Then build it and received two *.jars. I Included the boot.jar one into my dockerfile and deployed it. Unfortunately i get the same error
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
22-07-2020 08:05:01.610 ERROR org.springframework.boot.SpringApplication.reportFailure - Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'priceService': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [de.SWS.PLM.PriceParseService.services.PriceService] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader#7225790e]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:265)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1236)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1151)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:846)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at de.SWS.PLM.PriceParseService.PriceParseServiceApplication.main(PriceParseServiceApplication.java:17)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.lang.IllegalStateException: Failed to introspect Class [de.SWS.PLM.PriceParseService.services.PriceService] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader#7225790e]
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:686)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:583)
at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:568)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:248)
... 26 common frames omitted
Caused by: java.lang.NoClassDefFoundError: de/SWS/PLM/utils/ExcelCellTypeError
at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166)
at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309)
at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:668)
... 29 common frames omitted
Caused by: java.lang.ClassNotFoundException: de.SWS.PLM.utils.ExcelCellTypeError
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:93)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 33 common frames omitted
If i check the structure of the boot.jar it looks like
BOOT-INF
|
|---classes
| |---package.name
| |---project-a
| |---all the classes without the classes of project-b
|---lib
META-INF
org
So in both jars there are not the classes of project-b so project-a can not find the classes i think

Class not found exception in Spring boot application deployment to external tomcat

I have recently upgraded spring boot application from 1.3.1 to 1.5.10 version and Gradle from 2.7 to 3.5. I have fixed all the errors regarding upgrade and is working fine with IDE (STS). But when I am trying to deploy the war to external tomcat getting java.lang.NoClassDefFoundError: org/junit/rules/TestRule.
The application was working fine with old configuration only updated spring boot and Gradle version.
[ERROR] org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.projectx.SpringIntegrationApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class com.projectx.SpringIntegrationApplication
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class com.projectx.SpringIntegrationApplication
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163)
at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:380)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:314)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
... 26 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/junit/rules/TestRule
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2270)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1254)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152)
... 31 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.junit.rules.TestRule
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 42 common frames omitted
22-Jan-2020 12:35:33.963 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:724)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.projectx.SpringIntegrationApplication]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class com.projectx.SpringIntegrationApplication
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
at org.springframework.boot.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)
at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)
at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5178)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 10 more
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class com.projectx.SpringIntegrationApplication
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163)
at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:380)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:314)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
... 26 more
Caused by: java.lang.NoClassDefFoundError: org/junit/rules/TestRule
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2270)
at org.apache.catalina.loader.WebappClassLoaderBase.findClass(WebappClassLoaderBase.java:811)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1254)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethods(Class.java:1975)
at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152)
... 31 more
Caused by: java.lang.ClassNotFoundException: org.junit.rules.TestRule
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
... 42 more
22-Jan-2020 12:35:33.965 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive /usr/local/apache-tomcat-8.5.5/webapps/ROOT.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:728)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:700)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Gradle
buildscript {
ext {
// springBootVersion = '1.3.0.RELEASE'
springBootVersion = '1.5.10.RELEASE'
googleAPIClientVersion='1.2.3-alpha'
googleAPIClientJacksonVersion='1.23.0'
}
repositories {
jcenter()
mavenLocal()
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath ('org.asciidoctor:asciidoctor-gradle-plugin:1.5.2')
//classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
//apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
apply plugin: 'org.asciidoctor.convert'
war {
baseName = 'ROOT'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenLocal()
mavenCentral()
}
configurations {
providedRuntime
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-integration')
compile('org.springframework.boot:spring-boot-starter-web')
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile('org.springframework.integration:spring-integration-twitter:4.0.0.RELEASE')
compile('org.springframework.integration:spring-integration-java-dsl:1.0.0.RELEASE')
compile("org.springframework.boot:spring-boot-starter-data-mongodb")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile('org.springframework.boot:spring-boot-starter-security')
compile("mysql:mysql-connector-java:5.1.6")
compile('com.google.code.gson:gson:2.3')
compile('javax.interceptor:javax.interceptor-api:1.2')
compile('com.sun.mail:javax.mail:1.5.5')
compile('com.itextpdf:itextpdf:5.4.5')
compile('com.itextpdf.tool:xmlworker:5.5.6')
//excel sheet
compile ('org.apache.commons:commons-lang3:3.6')
compile ('org.dstadler:commons-dost:1.0.0.23')
compile ('com.google.guava:guava:21.0')
compile ('org.apache.commons:commons-csv:1.5')
compile 'org.apache.poi:poi:3.17'
compile 'org.apache.poi:poi-ooxml:3.17'
compile 'org.apache.poi:poi-scratchpad:3.17'
testCompile("com.jayway.jsonpath:json-path:1.1.0")
// testCompile('org.springframework.boot:spring-boot-starter-test')
// testCompile("org.mockito:mockito-core:1.+")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
compile("org.springframework.restdocs:spring-restdocs-mockmvc:1.1.1.RELEASE")
//compile('com.amazonaws:aws-java-sdk-s3:1.10.75')
//Deploy on same tomcat with diffrent domain dependancy
compile group: 'org.springframework.integration', name: 'spring-integration-jmx', version: '4.3.0.RELEASE'
//JJWT
compile ('io.jsonwebtoken:jjwt:0.6.0')
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
//AWS S3 SDK
compile group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.86'
//AWS SES SDK
compile group: 'com.amazonaws', name: 'aws-java-sdk-ses', version: '1.11.86'
//AWS SSM SDK
compile group: 'com.amazonaws', name: 'aws-java-sdk-ssm', version: '1.11.665'
//AWS EC2
compile group: 'com.amazonaws', name: 'aws-java-sdk-ec2', version: '1.11.665'
//SafetyNet
//compile group: 'com.google.api.client', name: 'google-api-client-json', version: googleAPIClientVersion
compile group: 'com.google.http-client', name: 'google-http-client-jackson2', version: googleAPIClientJacksonVersion
// https://mvnrepository.com/artifact/com.github.ulisesbocchio/jasypt-spring-boot-starter
compile group: 'com.github.ulisesbocchio', name: 'jasypt-spring-boot-starter', version: '1.9'
//Firebase
compile group: 'com.google.firebase', name: 'firebase-admin', version: '5.2.0'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-actuator
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('com.google.maps:google-maps-services:0.9.1')
// https://mvnrepository.com/artifact/org.springframework.integration/spring-integration-ip
compile group: 'org.springframework.integration', name: 'spring-integration-ip', version: '4.3.0.RELEASE'
compile('org.flywaydb:flyway-core')
//mysql connection pooling
compile group: 'com.zaxxer', name: 'HikariCP', version: '2.4.6'
}
eclipse {
classpath {
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
}
}
task wrapper(type: Wrapper) {
gradleVersion = '3.5'
}
ext {
snippetsDir = file('build/generated-snippets')
}
test {
outputs.dir snippetsDir
}
asciidoctor {
attributes 'snippets': snippetsDir
inputs.dir snippetsDir
dependsOn test
}
Guide me to diagnose this issue. Also want to know why tomcat loading junit class at run time.
Your suggestions will be highly appreciable.
Solved by adding compile time dependency for junit. I am unclrear why spring boot 1.5 need Junit dependency at runtime, If any know please explain it.

How to use spring data jpa with redshift

We have a redshift database with all the necessary data.
We are building materialized views on a MySQL database for our application, but until that is done I want to use the redshift DB for development.
My problem is that once I add the spring-boot-starter-data-jpa dependency, spring boot cant load the redshift driver.
I opened a new project to recreate the problem.
gradle.build:
buildscript {
ext {
springBootVersion = '2.1.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-
plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-
data-jpa'
compile 'com.amazonaws:aws-java-sdk-redshift:1.11.482'
compile 'com.amazon.redshift:redshift-jdbc42-no-
awssdk:1.2.18.1036'
}
application.properties:
spring.datasource.url=jdbc:redshift://redshift.url.com:5439/dbName
spring.datasource.username=user
spring.datasource.password=******
spring.datasource.driver-class-name=com.amazon.redshift.jdbc42.Driver
The Error I'm getting:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.amazon.redshift.jdbc42.Driver
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1308) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1154) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:392) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083) ~[spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:853) ~[spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at com.example.demo.DemoApplication.main(DemoApplication.java:10) [classes/:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.amazon.redshift.jdbc42.Driver
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1288) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:538) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1244) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1164) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
... 27 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.amazon.redshift.jdbc42.Driver
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
... 41 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot load driver class: com.amazon.redshift.jdbc42.Driver
at org.springframework.util.Assert.state(Assert.java:94) ~[spring-core-5.1.4.RELEASE.jar:5.1.4.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:224) ~[spring-boot-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.initializeDataSourceBuilder(DataSourceProperties.java:176) ~[spring-boot-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:43) ~[spring-boot-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:83) ~[spring-boot-autoconfigure-2.1.2.RELEASE.jar:2.1.2.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.1.4.RELEASE.jar:5.1.4.RELEASE]
... 42 common frames omitted
You also need to add Amazon's Redshift repository to your build.gradle file alongwith the dependency for downloading the respective jar.
repositories {
mavenCentral()
maven {
url "http://redshift-maven-repository.s3-website-us-east-1.amazonaws.com/release"
}
}

Spring Boot application fails after adding #EnableResourceServer

I trying to create a resource server that will authenticate every request by validating the access token in the header. Whenever I add #EnableResourceServer on my application class the application fails to run. Once I remove the annotation above the application runs again. The error says I have no implementation of JAXB-API on my classpath.
Here is the code of my application class:
package com.example.oauthimplicit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
#EnableWebSecurity
#EnableResourceServer
#SpringBootApplication
public class OauthImplicitApplication extends WebSecurityConfigurerAdapter{
public static void main(String[] args) {
SpringApplication.run(OauthImplicitApplication.class, args);
}
#Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/index.html", "/config").permitAll()
.anyRequest().authenticated();
}
}
Here is my build.gradle:
buildscript {
ext {
springBootVersion = '2.0.5.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
testImplementation('org.springframework.boot:spring-boot-starter-test')
implementation('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.security.oauth:spring-security-oauth2:2.3.3.RELEASE')
compile('javax.xml.bind:jaxb-api:2.3.0')
testImplementation('org.springframework.security:spring-security-test')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
When I run the application I get the following error:
2018-10-05 17:52:57.524 WARN 16921 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
2018-10-05 17:52:57.528 INFO 16921 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat]
2018-10-05 17:52:57.574 INFO 16921 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-10-05 17:52:57.586 ERROR 16921 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1247) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1096) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:535) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:495) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:304) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:759) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:780) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:412) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:333) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1277) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1265) [spring-boot-2.0.5.RELEASE.jar:2.0.5.RELEASE]
at com.example.oauthimplicit.OauthImplicitApplication.main(OauthImplicitApplication.java:18) [classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:582) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
... 20 common frames omitted
Caused by: java.lang.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
at org.springframework.security.oauth2.http.converter.jaxb.AbstractJaxbMessageConverter.<init>(AbstractJaxbMessageConverter.java:62) ~[spring-security-oauth2-2.3.3.RELEASE.jar:na]
at org.springframework.security.oauth2.http.converter.jaxb.JaxbOAuth2ExceptionMessageConverter.<init>(JaxbOAuth2ExceptionMessageConverter.java:21) ~[spring-security-oauth2-2.3.3.RELEASE.jar:na]
at org.springframework.security.oauth2.provider.error.DefaultOAuth2ExceptionRenderer.geDefaultMessageConverters(DefaultOAuth2ExceptionRenderer.java:117) ~[spring-security-oauth2-2.3.3.RELEASE.jar:na]
at org.springframework.security.oauth2.provider.error.DefaultOAuth2ExceptionRenderer.<init>(DefaultOAuth2ExceptionRenderer.java:53) ~[spring-security-oauth2-2.3.3.RELEASE.jar:na]
at org.springframework.security.oauth2.provider.error.AbstractOAuth2SecurityExceptionHandler.<init>(AbstractOAuth2SecurityExceptionHandler.java:42) ~[spring-security-oauth2-2.3.3.RELEASE.jar:na]
at org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint.<init>(OAuth2AuthenticationEntryPoint.java:36) ~[spring-security-oauth2-2.3.3.RELEASE.jar:na]
at org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer.<init>(ResourceServerSecurityConfigurer.java:62) ~[spring-security-oauth2-2.3.3.RELEASE.jar:na]
at org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration.configure(ResourceServerConfiguration.java:118) ~[spring-security-oauth2-2.3.3.RELEASE.jar:na]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.getHttp(WebSecurityConfigurerAdapter.java:230) ~[spring-security-config-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:321) ~[spring-security-config-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.init(WebSecurityConfigurerAdapter.java:92) ~[spring-security-config-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration$$EnhancerBySpringCGLIB$$3d845712.init(<generated>) ~[spring-security-oauth2-2.3.3.RELEASE.jar:na]
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.init(AbstractConfiguredSecurityBuilder.java:371) ~[spring-security-config-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.security.config.annotation.AbstractConfiguredSecurityBuilder.doBuild(AbstractConfiguredSecurityBuilder.java:325) ~[spring-security-config-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.security.config.annotation.AbstractSecurityBuilder.build(AbstractSecurityBuilder.java:41) ~[spring-security-config-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.springSecurityFilterChain(WebSecurityConfiguration.java:104) ~[spring-security-config-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$383bd88c.CGLIB$springSecurityFilterChain$3(<generated>) ~[spring-security-config-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$383bd88c$$FastClassBySpringCGLIB$$6f7b245e.invoke(<generated>) ~[spring-security-config-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:365) ~[spring-context-5.0.9.RELEASE.jar:5.0.9.RELEASE]
at org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration$$EnhancerBySpringCGLIB$$383bd88c.springSecurityFilterChain(<generated>) ~[spring-security-config-5.0.8.RELEASE.jar:5.0.8.RELEASE]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
... 21 common frames omitted
Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:278) ~[jaxb-api-2.3.0.jar:2.3.0]
at javax.xml.bind.ContextFinder.find(ContextFinder.java:421) ~[jaxb-api-2.3.0.jar:2.3.0]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721) ~[jaxb-api-2.3.0.jar:2.3.0]
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662) ~[jaxb-api-2.3.0.jar:2.3.0]
at org.springframework.security.oauth2.http.converter.jaxb.AbstractJaxbMessageConverter.<init>(AbstractJaxbMessageConverter.java:59) ~[spring-security-oauth2-2.3.3.RELEASE.jar:na]
... 46 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) ~[na:na]
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190) ~[na:na]
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499) ~[na:na]
at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122) ~[jaxb-api-2.3.0.jar:2.3.0]
at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155) ~[jaxb-api-2.3.0.jar:2.3.0]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:276) ~[jaxb-api-2.3.0.jar:2.3.0]
... 50 common frames omitted
Process finished with exit code 1
I've just fixed the same issue: after visiting the dependency page of (a quite new version of) Spring Security OAuth2 AutoConfigure (https://mvnrepository.com/artifact/org.springframework.security.oauth.boot/spring-security-oauth2-autoconfigure/2.1.0.RELEASE) I decided to put/refresh all JAXB API related dependencies:
// Java 11
runtime('com.sun.xml.bind:jaxb-core:2.3.0.1')
runtime('com.sun.xml.bind:jaxb-impl:2.3.1')
runtime('javax.xml.bind:jaxb-api:2.3.1')
runtime('org.javassist:javassist:3.23.1-GA')
Now it works fine, hope it helps.
If you use Java 9 or higher you need to add this VM options in your Tomcat configuration
--add-modules
java.xml.bind
I was following a Udemy course on CQRS and Event sourcing and the instructor create an OAuth 2.0 server but when i ran the auth server it kept failing with this error. i tried everything, the only thing that worked is adding
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.28.0-GA</version>
</dependency>
Without this i kept getting the exception
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'springSecurityFilterChain' defined in class path resource [org/springframework/security/config/annotation/web/configuration/WebSecurityConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.servlet.Filter]: Factory method 'springSecurityFilterChain' threw exception; nested exception is java.lang.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.8.jar:5.3.8]
So thank you. I am totally new to spring boot and oauth 2.0 type implementation and i was trying to wrack my brains on it and knew it wasnt something that i did different from the instructor.. it somehow worked for him on an older version of spring and java 14 but i am on spring 2.5+ and java 16

Error processing condition on org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration

After adding 2 dependencies shown below to my application everything works fine my session data is written to my local redis server, but when i try to specify different address of redis server i got an error. I assume that error is connected with some dependencies problem, but i dont know how to tackle this issue.
compile "org.springframework.boot:spring-boot-starter-data-redis-reactive:${springVersion}"
compile "org.springframework.session:spring-session-data-redis:${springVersion}"
Error during startup
java.lang.IllegalStateException: Error processing condition on
org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration.propertySourcesPlaceholderConfigurer
at
org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:64)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:180)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:141)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:117)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:328)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:233)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:273)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:694)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:532)
~[spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:61)
~[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
[spring-boot-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
pl.bk.pizza.store.Initializer.main(Initializer.java:11) [classes/:na]
Caused by: java.lang.IllegalStateException: Failed to introspect Class
[org.springframework.session.config.annotation.web.http.SpringHttpSessionConfiguration]
from ClassLoader [sun.misc.Launcher$AppClassLoader#18b4aac2] at
org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:556)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:569)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:541)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:599)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:724)
~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:665)
~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:633)
~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1489)
~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1012)
~[spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE] at
org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.addBeanTypeForNonAliasDefinition(BeanTypeRegistry.java:164)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.addBeanType(BeanTypeRegistry.java:153)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.updateTypesIfNecessary(BeanTypeRegistry.java:203)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.BeanTypeRegistry.getNamesForType(BeanTypeRegistry.java:115)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:265)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:254)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:196)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:116)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] at
org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47)
~[spring-boot-autoconfigure-2.0.2.RELEASE.jar:2.0.2.RELEASE] ... 17
common frames omitted Caused by: java.lang.NoClassDefFoundError:
javax/servlet/Filter at java.lang.ClassLoader.defineClass1(Native
Method) ~[na:1.8.0-internal] at
java.lang.ClassLoader.defineClass(ClassLoader.java:763)
~[na:1.8.0-internal] at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
~[na:1.8.0-internal] at
java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
~[na:1.8.0-internal] at
java.net.URLClassLoader.access$100(URLClassLoader.java:73)
~[na:1.8.0-internal] at
java.net.URLClassLoader$1.run(URLClassLoader.java:368)
~[na:1.8.0-internal] at
java.net.URLClassLoader$1.run(URLClassLoader.java:362)
~[na:1.8.0-internal] at
java.security.AccessController.doPrivileged(Native Method)
~[na:1.8.0-internal] at
java.net.URLClassLoader.findClass(URLClassLoader.java:361)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:424)
~[na:1.8.0-internal] at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:357)
~[na:1.8.0-internal] at java.lang.ClassLoader.defineClass1(Native
Method) ~[na:1.8.0-internal] at
java.lang.ClassLoader.defineClass(ClassLoader.java:763)
~[na:1.8.0-internal] at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
~[na:1.8.0-internal] at
java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
~[na:1.8.0-internal] at
java.net.URLClassLoader.access$100(URLClassLoader.java:73)
~[na:1.8.0-internal] at
java.net.URLClassLoader$1.run(URLClassLoader.java:368)
~[na:1.8.0-internal] at
java.net.URLClassLoader$1.run(URLClassLoader.java:362)
~[na:1.8.0-internal] at
java.security.AccessController.doPrivileged(Native Method)
~[na:1.8.0-internal] at
java.net.URLClassLoader.findClass(URLClassLoader.java:361)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:424)
~[na:1.8.0-internal] at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:357)
~[na:1.8.0-internal] at java.lang.Class.getDeclaredMethods0(Native
Method) ~[na:1.8.0-internal] at
java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
~[na:1.8.0-internal] at
java.lang.Class.getDeclaredMethods(Class.java:1975)
~[na:1.8.0-internal] at
org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641)
~[spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE] ... 35 common frames
omitted Caused by: java.lang.ClassNotFoundException:
javax.servlet.Filter at
java.net.URLClassLoader.findClass(URLClassLoader.java:381)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:424)
~[na:1.8.0-internal] at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
~[na:1.8.0-internal] at
java.lang.ClassLoader.loadClass(ClassLoader.java:357)
~[na:1.8.0-internal] ... 63 common frames omitted
RedisConfig
#Configuration
#EnableRedisHttpSession
public class RedisConfig
{
#Bean
LettuceConnectionFactory jedisConnectionFactory()
{
final RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
config.setHostName("redis-19999.c14.us-east-1-2.ec2.cloud.redislabs.com");
config.setPort(19999);
config.setPassword(RedisPassword.of("***"));
return new LettuceConnectionFactory();
}
}
build.gradle file
buildscript {
ext.springVersion = '2.0.2.RELEASE'
ext.gradleDocker = '1.2'
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath "se.transmode.gradle:gradle-docker:$gradleDocker"
classpath "org.springframework.boot:spring-boot-gradle-plugin:$springVersion"
}
}
plugins {
id "org.sonarqube" version "2.6.2"
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'groovy'
apply plugin: 'org.springframework.boot'
apply plugin: 'docker'
apply plugin: 'jacoco'
dependencies {
// spring
compile "org.springframework.boot:spring-boot-starter-webflux:${springVersion}"
compile "org.springframework.boot:spring-boot-starter-data-mongodb-reactive:${springVersion}"
compile "org.springframework.boot:spring-boot-starter-security:${springVersion}"
testCompile "org.springframework.security:spring-security-test:${springSecurityTest}"
testCompile "org.springframework.boot:spring-boot-starter-test:${springVersion}"
compile "org.springframework.boot:spring-boot-starter-data-redis-reactive:${springVersion}"
compile "org.springframework.session:spring-session-data-redis:${springVersion}"
// utils
testCompile "org.assertj:assertj-core:${assertJ}"
compile "com.google.guava:guava:${guava}"
compile "io.projectreactor:reactor-core:${reactor}"
compile "io.reactivex.rxjava2:rxjava:${rxjava}"
compile "commons-lang:commons-lang:${commonsLang}"
compile "commons-validator:commons-validator:${commonsLangValidator}"
compileOnly "org.projectlombok:lombok:${lombok}"
// embedded mongo for tests
testCompile "de.flapdoodle.embed:de.flapdoodle.embed.mongo:${embeddedMongo}"
// spock
compile "org.codehaus.groovy:groovy-all:${groovy}"
testCompile "org.spockframework:spock-core:${spockCore}"
testCompile "org.spockframework:spock-spring:${spockSpring}"
}
There are several thing going on here.
The log you've supplied indicates javax.servlet.Filter is missing from the classpath while your build script and dependencies suggest your building a Spring WebFlux app. I suspect this is due to you explicitly configuring Spring Session's Servlet support using #EnableRedisHttpSession (notice HttpSession in there?) rather than #EnableRedisWebSession. Even better, you should leave Spring Session configuration to Spring Boot to auto-configure it - see Spring Session dedicated section of Spring Boot's reference manual.
The same advice (avoid explicit config, rely on auto-config) applies to your Redis configuration i.e. no need for that explicit LettuceConnectionFactory bean.
Furthermore, with Spring Boot, it's highly recommended to use its dependency management, rather then providing the versions of your dependency explicitly, at least for the dependencies that are covered by Spring Boot's dependency management. Refer to dependency management and dependency versions appendix sections of Boot's reference manual. On top of that, you should also strongly consider using Boot's starters to make sure all the required dependencies are pulled in - see starters dedicated section.
This same error message presents if you create an application via spring initializr , specify Session as a dependency, create a #RestController and then use #EnableSpringHttpSession.
Without using #EnableSpringHttpSession, the application will start and exit, with no stack trace. This gives the appearance that perhaps there is something wrong with the HttpSession configuration.
The actual cause of the error condition is due to not having included Web as an application dependency (or implementation('org.springframework.boot:spring-boot-starter-web' in build.gradle)
For me ,Everything is perfect but it still throws the exception-Propertyplaceholderautoconfiguration
I just tried maven reload and project reload ,still it throws this error and shows some red lines on dependency Class which is I used to import and used it in my project files
Just closed IntelliJ and opened the project again,Then Everything works fine.
Thumbs up,If it is useful to you

Resources