problems with getting basic logging up with springboot and logback - spring

i have a simple spring boot app in groovy. here are the gradle dependencies i have set so far
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
compile 'org.easyrules:easyrules-core:2.2.1-SNAPSHOT'
compile 'org.easyrules:easyrules-spring:2.2.1-SNAPSHOT'
compile 'org.easyrules:easyrules-jmx:2.2.1-SNAPSHOT'
testCompile group: 'junit', name: 'junit', version: '4.11'
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-starter-logging'
compile 'ch.qos.logback:logback-classic:1.1.5'
}
this brings in slf4j-api, log4j-over-slf4j, jul-to-slf4j, and jcl-over-slf4f at versions 1.7.13
then in my helper class i have this
#Component
#PropertySource ("classpath:application.properties")
class RulesHelper {
private static final Logger log = LoggerFactory.getLogger(RulesHelper.class)
followed by a bean def like this
#Bean
def rulesEngine () {
assert jmxEnabled != null
if ( !jmxEnabled ) {
//return std rules engine
println "returning std rules engine of type ${stdRulesEngine.getClass().name}"
ruleEngine = stdRulesEngine
return stdRulesEngine
} else {
println "returning jmx rules engine of type ${jmxRulesEngine.getClass().name}"
//log.debug("hello from logger")
//assert log
ruleEngine = jmxRulesEngine
return jmxRulesEngine //JmxRulesExtends RulesEngine so should work
}
}
if i uncomment out that assert i get an error when i run like this saying it cant find org.slf4j.event.LoggingEvent
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.lang.Object]: Factory method 'rulesEngine' threw exception; nested exception is java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 26 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent
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.codehaus.groovy.reflection.CachedClass$3$1.run(CachedClass.java:85)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:82)
at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:80)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
at org.codehaus.groovy.reflection.CachedClass.getMethods(CachedClass.java:251)
at groovy.lang.MetaClassImpl.populateMethods(MetaClassImpl.java:361)
at groovy.lang.MetaClassImpl.fillMethodIndex(MetaClassImpl.java:340)
at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:3224)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:222)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:253)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:263)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:259)
at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:855)
at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:888)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:880)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToBoolean(DefaultTypeTransformation.java:180)
at org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.booleanUnbox(DefaultTypeTransformation.java:69)
at org.softwood.easyrules.RulesHelper.rulesEngine(RulesHelper.groovy:79)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 27 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.slf4j.event.LoggingEvent
what have i done wrong here - i thought this would work based on what i have read

well what do you know - dependency management issue - the latest springboot-starter-logging is only using slf4j-api.1.7.13,
however if you get the latest logback which i did logback_classic.1.1.5 there was breaking issue somewhere in the Api client librray that didnt export the class - which is why it couldnt be found. see logback issue/news
if you explicitly add the dependency
...
compile 'ch.qos.logback:logback-classic:1.1.5'
compile 'org.slf4j:slf4j-api:1.7.16'
to gradle.build, refresh and retry it all starts to work as nature expected. Blimey painful as usual as these things normally are

java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent
Logback-classic version 1.1.4 and later require slf4j-api version 1.7.15 or later.
With an earlier slf4j-api.jar in the classpath, attempting introspection of a Logger instance returned by logback version 1.1.4 or later will result in a NoClassDefFoundError similar to that shown below.
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/event/LoggingEvent
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.privateGetPublicMethods(Class.java:2571)
at java.lang.Class.getMethods(Class.java:1429)
at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1261)
at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1122)
at java.beans.Introspector.getBeanInfo(Introspector.java:414)
at java.beans.Introspector.getBeanInfo(Introspector.java:161)
Placing slf4j-api.jar version 1.7.15 or later in the classpath should solve the issue.
Note that this problem only occurs with logback version 1.1.4 and later, other bindings such as slf4j-log4j, slf4j-jdk14 and slf4j-simple are unaffected.

corresponding maven dependency missing got it from https://mvnrepository.com/artifact/org.slf4j/slf4j-api/1.7.15
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.15</version>
</dependency>

Related

failed to build spingboot with swagger 2.0

I am relatively new to spring. I tried to add API documentation with Swagger-2.0 and I no longer able to build
I failed to build with "gradlew build"
> getProductById FAILED
java.lang.IllegalStateException
Caused by: org.springframework.context.ApplicationContextException
Caused by: java.lang.NoSuchMethodError
Caused by: org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NoSuchMethodError: 'org.springframework.plugin.core.Plugin org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor(java.lang.Object, org.springframework.plugin.core.Plugin)'
Caused by: java.lang.NoSuchMethodError: 'org.springframework.plugin.core.Plugin org.springframework.plugin.core.PluginRegistry.getPluginOrDefaultFor(java.lang.Object, org.springframework.plugin.core.Plugin)'
In build.gradle I added :
repositories {
mavenCentral()
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
maven { url 'http://oss.jfrog.org/artifactory/oss-snapshot-local/' }
}
dependencies {
implementation project(':api')
implementation project(':util')
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-webflux')
implementation('io.springfox:springfox-swagger2:3.0.0-SNAPSHOT')
implementation('io.springfox:springfox-swagger-ui:3.0.0-SNAPSHOT')
implementation('io.springfox:springfox-spring-webflux:3.0.0-SNAPSHOT')
testImplementation('org.springframework.boot:spring-boot-starter-test')
testImplementation('io.projectreactor:reactor-test')
}
Where should I look to find the root cause ?

Can't Get Elasticsearch Plugin to Work with Grails 3

I've tried to hook up Elasticsearch plugin ('org.grails.plugins:elasticsearch:1.4.1') with a Grails 3.1.9 project without any luck.
I've also uploaded a simple application in github to demonstrate the issue (https://github.com/jackiebai/testEs)
The above sample testing app only has 1 domain class called Person:
class Person {
String name
static searchable = true
static constraints = {
}
}
The corresponding service class PersonService is used to save and index the Person data:
import grails.transaction.Transactional
#Transactional
class PersonService {
def addPerson(Person person){
person.save()
person.index()
}
def addPerson(String name) {
Person p = new Person(name:name)
addPerson(p)
}
}
I've also added a couple of lines of code in the BootStrap.groovy so that some data will get inserted into the default hibernate db when the application starts:
class BootStrap {
def personService
def init = { servletContext ->
personService.addPerson("Person One")
personService.addPerson("John Smith")
}
def destroy = {
}
}
The application.yml variable settings for the development environment look like below:
environments:
development:
dataSource:
dbCreate: create-drop
url: jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE
elasticSearch:
client:
mode: node
transport.sniff: true
bulkIndexOnStartup: true
datastoreImpl: hibernateDatastore
Additional dependencies and bootRun code block were included in the build.gradle by following the plugin user guide (http://noamt.github.io/elasticsearch-grails-plugin/docs/index.html)
dependencies {
...
compile 'org.grails.plugins:elasticsearch:1.4.1'
compile 'org.elasticsearch:elasticsearch:5.4.1'
...
}
bootRun{
jvmArgs = ['-Des.path.home=/Users/myname/elasticsearch-5.4.1']
}
Unfortunately the application failed to run under my osx 10.11.6,java 1.8.0_91 environment with below errors:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'elasticSearchClient': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/mapper/attachments/MapperAttachmentsPlugin
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:175)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:103)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1590)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:317)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:351)
... 34 common frames omitted
Caused by: java.lang.NoClassDefFoundError: org/elasticsearch/mapper/attachments/MapperAttachmentsPlugin
at grails.plugins.elasticsearch.ClientNodeFactoryBean.getObject(ClientNodeFactoryBean.groovy:207)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:168)
... 39 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.mapper.attachments.MapperAttachmentsPlugin
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 41 common frames omitted
According to documentation you should use v1.2.0
https://github.com/noamt/elasticsearch-grails-plugin
I believe version 1.4.1 is broken. You can try 2.4.0.RC1 with Grails 3.3+ but you need to add dependency to mapper-attachments and specify elasticsearch.version for Spring Boot:
ext['elasticsearch.version'] = '5.4.1'
dependencies {
compile 'org.grails.plugins:elasticsearch:2.4.0.RC1'
runtime 'org.elasticsearch.plugin:mapper-attachments:2.4.6'
}
See issue#198

Spring Data Rest and spring-data-rest-hal-browser integration using Spring Boot

Problem
The Spring Data REST Reference Documentation says that
dependencies {
compile 'org.springframework.data:spring-data-rest-hal-browser'
}
is enough to integrate HAL browser with Spring Data Rest while using Spring Boot but Gradle complains this dependency cannot be found unless I specify particular version so I fixed it by specifying the latest one available in central repository (there is no other version available in the repository). After specifying the version the dependency is resolved but I get an error during Spring Boot container initialization:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.repository.support.Repositories]: Factory method 'repositories' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cameraRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 151 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cameraRepository': Invocation of init method failed; nested exception is java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1572)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:966)
at org.springframework.data.repository.support.Repositories.cacheRepositoryFactory(Repositories.java:95)
at org.springframework.data.repository.support.Repositories.populateRepositoryFactoryInformation(Repositories.java:88)
at org.springframework.data.repository.support.Repositories.<init>(Repositories.java:81)
at org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration.repositories(RepositoryRestMvcConfiguration.java:182)
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0.CGLIB$repositories$11(<generated>)
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0$$FastClassBySpringCGLIB$$ec6a4119.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
at org.springframework.boot.autoconfigure.data.rest.SpringBootRepositoryRestMvcConfiguration$$EnhancerBySpringCGLIB$$b6ea42c0.repositories(<generated>)
at sun.reflect.NativeMetssorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 152 more
Caused by: java.lang.AbstractMethodError: org.springframework.data.repository.core.support.RepositoryFactorySupport.getTargetRepository(Lorg/springframework/data/repository/core/RepositoryInformation;)Ljava/lang/Object;
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:185)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1631)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1568)
... 173 more
However my application initializes successfully and works as expected if I remove spring-data-rest-hal-browser:2.4.0.RELEASE dependency.
Question
How can I setup my build.gradle correctly to have my application integrated with HAL browser properly?
build.gradle
buildscript {
ext {
springBootVersion = '1.2.7.RELEASE'
}
repositories {
mavenCentral()
}
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath('io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE')
}
[...]
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-remote-shell')
compile('org.springframework.data:spring-data-rest-hal-browser:2.4.0.RELEASE')
compile('org.projectlombok:lombok:1.16.6')
compile name: 'ojdbc6'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc:1.0.0.RELEASE')
}
The automatic version management for the HAL browser only works starting with Spring Boot 1.3.0 which is at the release candidate stage and should be released very soon. The release candidate is very stable for me, so you may consider giving that a try by updating your build to 1.3.0.RC1 which I would expect would fix the issue, something like this:
buildscript {
ext {
springBootVersion = '1.3.0.RC1'
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone/' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "io.spring.gradle:dependency-management-plugin:0.5.2.RELEASE"
}
}
repositories {
mavenCentral()
flatDir {
dirs 'lib'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-data-rest')
compile('org.springframework.boot:spring-boot-starter-remote-shell')
compile('org.springframework.data:spring-data-rest-hal-browser')
compile('org.projectlombok:lombok:1.16.6')
compile name: 'ojdbc6'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('org.springframework.restdocs:spring-restdocs-mockmvc')
}
You can see the managed dependency versions for 1.3.0.RC1 here:
http://docs.spring.io/spring-boot/docs/1.3.0.RC1/reference/htmlsingle/#appendix-dependency-versions
You'll notice if you look at the managed dependency versions for 1.2.7 that neither spring-data-rest-hal-browser nor spring-restdocs-mockmvc are present.
The package was renamed to spring-data-rest-hal-explorer. Here's an example of a modern configuration of HAL with Spring Boot 2 with automatic version management.
Maven example:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-rest-hal-explorer</artifactId>
</dependency>
Gradle example:
plugins {
id "io.spring.dependency-management" version <<version>>
}
dependencies {
implementation('org.springframework.data:spring-data-rest-hal-explorer')
}

java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration

I am trying to write a standalone executable jar (fat jar) . I am using spring boot gradle plugin and writing a SpringBoot App to do this.
Here is my Application.java file
#Configuration
#EnableAutoConfiguration
#EnableRabbit
#EntityScan("persistence.domain")
#EnableJpaRepositories("persistence.repository")
#ComponentScan(basePackages = {"common","service"})
public class Application {
public static void main(final String[] args) {
final SpringApplicationBuilder appBuilder = new SpringApplicationBuilder(
Application.class);
appBuilder.profiles("common", "common_db").run(args);
}
#Bean
#Primary
#ConfigurationProperties(prefix = "spring.datasource")
public DataSource primaryDataSource() {
return DataSourceBuilder.create().build();
}
}
I have specified properties in yml files. For ex application-common etc . While running Application.java I am getting error :
[2015-09-24 14:40:22.304] boot - 32791 INFO [main] ---AnnotationConfigEmbeddedWebApplicationContext: Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#51a282af: startup date [Thu Sep 24 14:40:22 IST 2015]; root of context hierarchy
[2015-09-24 14:40:23.194] boot - 32791 WARN [main] --- AnnotationConfigEmbeddedWebApplicationContext: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: ; nested exception is java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:392)
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:165)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:305)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:243)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:254)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:94)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:611)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:109)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142)
at storm.Application.main(Application.java:28)
Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:58)
at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:92)
at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:190)
at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:435)
at org.springframework.context.annotation.ConfigurationClassParser.processDeferredImportSelectors(ConfigurationClassParser.java:389)
... 12 more
Caused by: java.lang.NullPointerException
at org.springframework.boot.autoconfigure.condition.OnPropertyCondition.getMatchOutcome(OnPropertyCondition.java:61)
at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:45)
... 16 more
Here is my build.gradle
def projects= [
":common",
":persistence",
":adapter"
]
buildscript {
repositories {
mavenCentral()
maven { url 'http://repo.spring.io/snapshot' }
maven { url 'http://repo.spring.io/milestone' }
}
dependencies { classpath group: 'org.springframework.boot', name: 'spring-boot-gradle-plugin', version: springBootVersion }
}
apply plugin: 'spring-boot'
apply plugin: 'maven-publish'
apply from: "${rootDir}/deployTasks.gradle"
springBoot {
mainClass = "storm.Application"
}
dependencies {
compile project(':common')
compile project(':adapter')
compile project(':persistence')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version: '1.1.8.RELEASE'
compile group : 'org.springframework.boot',name: 'spring-boot-autoconfigure', version : '1.1.8.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.1.8.RELEASE'
}
Database specification as in application-common_db.yml
database:
host: localhost
port: 3306
schema: subscriptions
username: root
password: root
autoconnect:
maxReconnects: 3
initialTimeout: 2
timeout:
connectTimeout: 0
socketTimeout: 0
failover:
host: localhost
port: 3306
queriesBeforeRetryMaster: 50
secondsBeforeRetryMaster: 30
spring:
datasource:
driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://${database.host}:${database.port},${database.failover.host}:${database.failover.port}/${database.schema}?${database.properties}
username: ${database.username}
password: ${database.password}
continueOnError: true
initialize: false
initialSize: 0
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 5000
removeAbandonedTimeout: 60
removeAbandoned: true
minIdle: 0
I am not sure how to resolve this error . Can nybody suggest what is going wrong here and why am i getting nullPointerException.
Help is appreciated .
Thanks
This is caused by non-matching Spring Boot dependencies. Check your classpath to find the offending resources. You have explicitly included version 1.1.8.RELEASE, but you have also included 3 other projects. Those likely contain different Spring Boot versions, leading to this error.
I know this is quite an old one, but I faced similar issue and resolved it in a different way. The actuator-autoconfigure pom somehow was invalid and so it was throwing IllegalStateException. I removed the actuator* dependencies from my maven repo and did a Maven update in eclipse, which then downloaded the correct/valid dependencies and resolved my issue.
In my case I had created a SB app from the SB Initializer and had included a fair number of deps in it to other things. I went in and commented out the refs to them in the build.gradle file and so was left with:
implementation 'org.springframework.boot:spring-boot-starter-hateoas'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'org.hsqldb:hsqldb'
runtimeOnly 'org.postgresql:postgresql'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
as deps. Then my bare-bones SB app was able to build and get running successfully. As I go to try to do things that may need those commented-out libs I will add them back and see what breaks.
This error is because of multiple projects having the offending resources.
Try out adding the dependencies projects another way around. (like in pom.xml or external dependencies)
I had the same its because of hibernate-core version issue when you remove the version so it resolve the problem you should try it.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
If it's a new project, make sure you remembered to add spring starter web dependency
I had the same its because of version incompatibility check for version or remove version if using spring boot

Gradle built jar does not find my main class

At work we use gradle on a Scalding project and I'm trying to come up with the simplest job to get the hand out of the stack.
My class looks as :
package org.playground
import com.twitter.scalding._
class readCsv(args: Args) extends Job(args) {
val csv:Csv = Csv(args("input"), ("firstName", "lastName"))
println(csv)
}
and lives in playground/src/org/playground/readCsv.scala. My build script looks like this:
apply plugin: 'scala'
archivesBaseName = 'playground'
mainClassName = 'org.playground.readCsv'
repositories {
mavenLocal()
mavenCentral()
maven{
url 'http://conjars.org/repo/'
artifactUrls 'http://clojars.org/repo/‎'
artifactUrls 'http://maven.twttr.com/'
}
}
dependencies {
compile 'org.scala-lang:scala-compiler:2.9.2'
compile 'org.scala-lang:scala-library:2.9.2'
compile 'bixo:bixo-core:0.9.1'
compile 'org.apache.hadoop:hadoop-core:1.2.1'
compile 'com.twitter:scalding_2.9.2:0.8.1'
compile 'cascading:cascading-core:2.1.6'
compile 'cascading:cascading-hadoop:2.1.6'
testCompile 'org.testng:testng:6.8.7'
testCompile 'org.scala-tools.testing:specs:1.6.2.2_1.5.0'
}
test {
useTestNG()
}
jar {
description = "Assembles a Hadoop-ready JAR file"
manifest {
attributes( "Main-Class": "org.playground.readCsv" )
}
}
This compiles and builds successfully but trying to run the jar throws this error:
$ java -jar build/libs/playground.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/playground/readCsv
Caused by: java.lang.ClassNotFoundException: org.playground.readCsv
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
My educated guess is that having the job extend from Job fails to conform some convention and doesn't look like a valid Main-Class, but I won't expect it to complain about not finding it.
Other possibility is that running it as java -jar jarname is incorrect and I just need run it with hadoop or something along those lines.
Anyway and just to validate: What is wrong with my setup?
The source file is in the wrong location. By default, it needs to go into src/main/scala/org/playground/readCsv.scala. Otherwise, it won't even get compiled.

Resources