Grails 3 throwing strange exception when using more than 14 Domain classes with #Resource - grails

Grails 3 is throwing a strange exception when using REST Resources. What I have noticed is that when I have more than 14 Domain classes with the #Resource annotation it is throw a weird exception and refuses to start with the run-app command. I have checked in code to a github repo to demonstrate the problem. If you get this project and do a grails run-app it will throw an exception. I am using JDK 7 and grails 3.0.4.
Github repo: https://github.com/akhopkar/testREST
The Exception it throws is:
ERROR grails.boot.GrailsApp - Application startup failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.test.A2Controller': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Comparison method violates its general contract!

Related

Spring boot fiegn client

Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'feignEncoder' defined in org.springframework.cloud.openfeign.FeignClientsConfiguration:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to instantiate [feign.codec.Encoder]: Factory method 'feignEncoder' threw exception; nested exception is
java.lang.NoClassDefFoundError: feign/form/FormEncoder
This happened due to incorrect dependency jars. I deleted my local .m2 folder and build the project again and it is working fine now.

Grails 3 hibernateDatastore stratup error after migrating from Grails 2

I am upgrading to Grails 3.3.1 from a Grails 2.4 app.
Things seemed to be going slow but OK until I stumbled into this problem when trying to run the app:
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Configuring Spring Security Shiro ...
... finished configuring Spring Security Shiro
2017-12-19 18:51:43.400 ERROR --- [ost-startStop-1] o.s.b.c.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'grailsCacheFilter': Cannot create inner bean '(inner bean)#3238926e' of type [grails.plugin.cache.web.filter.simple.MemoryPageFragmentCachingFilter] while setting bean property 'filter'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)#3238926e': Unsatisfied dependency expressed through method 'setUrlMappingsHandlerMapping' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'urlMappingsHandlerMapping': Unsatisfied dependency expressed through method 'setWebRequestInterceptors' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'openSessionInViewInterceptor': Cannot resolve reference to bean 'hibernateDatastore' while setting bean property 'hibernateDatastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateDatastore': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.grails.orm.hibernate.HibernateDatastore]: Constructor threw exception; nested exception is java.lang.ExceptionInInitializerError
2017-12-19 18:51:43.492 ERROR --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
grailsCacheFilter
↓
(inner bean)#3238926e
↓
urlMappingsHandlerMapping
↓
openSessionInViewInterceptor
┌─────┐
| hibernateDatastore
└─────┘
Hibernate and Shiro version in the build gradle:
// hibernate
compile "org.grails.plugins:hibernate5:6.0.13"
compile "org.hibernate:hibernate-core:5.1.10.Final"
compile "org.hibernate:hibernate-ehcache:5.1.10.Final"
compile 'org.grails.plugins:spring-security-shiro:3.0.1'
Is this a common error people are running into?
Will I have to go through my dependences one by one to see if one of them is causing this?

Issue while upgrading Grails to 2.4.0 from 2.1.4 & JDK to 1.8 from 1.7

We have an application which was implemented by grails 2.1.4 & JDK 1.7 which we need to migrate to grails 2.4.0 and JDK 1.8.
While updating to grails 2.4.0, below are the changes done from our end.
Updated all plugins in BuildConfig.groovy and application.properties files.
Many classes are deprecated, so I have used grails.util.Holders class instead of below deprecated classes.
org.codehaus.groovy.grails.commons.ApplicationHolder
org.codehaus.groovy.grails.commons.ConfigurationHolder
org.codehaus.groovy.grails.plugins.PluginManagerHolder
For few classes, I have changed the import packages as per grails 2.4.0
Latest richUI plugin is not available, so I have updated Holders class instead of ConfigurationHolder in richUI plugin groovy classes.
Built the war successfully and deployed war in tomcat.
Issue is unable to redirect the link from urlmappings.groovy to home controller and appropriate gsp.
Tried to redirect to another gsp within project(index.gsp) but it couldn’t.
Created new gsp(hello.gsp) and redirect to hello.gsp from urlmappings.groovy but it did not work.
When trying to load the application URL http://localhost:8080/abc, it will redirect to http://localhost:8080/abc/login/auth showing page cannot be displayed
While debugging, control goes from urlmappings.groovy to bootstrap.groovy and further it is not navigating anywhere.
Any help appreciated. Thanks in advance
Adding Urlmappings.groovy
static mappings = { "/$controller/$action?/$id?"{ constraints { // apply constraints here } } // Home "/"(controller:"home",action:"index") // Reports service urls "/services/report"(controller: "BirtReport"){ action=[GET:"list"] } "500"(view:'/error') }
While running the application I am receiving the below error in the stacktrace.log
ERROR context.GrailsContextLoaderListener - Error initializing the application: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsServiceClass
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pluginManager' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsServiceClass
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Unable to locate constructor with Class parameter for class org.codehaus.groovy.grails.commons.DefaultGrailsServiceClass
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
... 4 more
Caused by: java.lang.NoClassDefFoundError: org/pentaho/di/core/logging/LogLevel
at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
at java.lang.Class.getDeclaredMethods(Class.java:1967)
... 4 more
Caused by: java.lang.ClassNotFoundException: org.pentaho.di.core.logging.LogLevel
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more

Searchable grails plugin ClassNotFoundException: org.apache.lucene.analysis.Analyzer$TokenStreamComponents

i'm using the searchable 0.6.9 plugin with grails 2.4.4 and on my development machine (Windows/IntelliJ IDEA) everything works fine. Deploying it on my Tomcat on linux, however, gives me the following error:
...
2014-12-01 10:20:46,066 [localhost-startStop-1] ERROR StackTrace - Full Stack Trace:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grails.plugin.searchable.SearchableController': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'searchableService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compass': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: org/apache/lucene/analysis/Analyzer$TokenStreamComponents
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask.run(FutureTask.java:262)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'searchableService': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compass': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: org/apache/lucene/analysis/Analyzer$TokenStreamComponents
... 5 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'compass': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: org/apache/lucene/analysis/Analyzer$TokenStreamComponents
... 5 more
Caused by: java.lang.NoClassDefFoundError: org/apache/lucene/analysis/Analyzer$TokenStreamComponents
at org.compass.core.lucene.engine.analyzer.CoreAnalyzerBuilderDelegate.buildAnalyzer(CoreAnalyzerBuilderDelegate.java:47)
at org.compass.core.lucene.engine.analyzer.DefaultLuceneAnalyzerFactory.createAnalyzer(DefaultLuceneAnalyzerFactory.java:81)
at org.compass.core.lucene.engine.analyzer.LuceneAnalyzerManager.buildAnalyzer(LuceneAnalyzerManager.java:225)
at org.compass.core.lucene.engine.analyzer.LuceneAnalyzerManager.buildAnalyzers(LuceneAnalyzerManager.java:133)
at org.compass.core.lucene.engine.analyzer.LuceneAnalyzerManager.<init>(LuceneAnalyzerManager.java:67)
at org.compass.core.lucene.engine.LuceneSearchEngineFactory.<init>(LuceneSearchEngineFactory.java:119)
at org.compass.core.impl.DefaultCompass.<init>(DefaultCompass.java:124)
at org.compass.core.impl.DefaultCompass.<init>(DefaultCompass.java:117)
at org.compass.core.config.CompassConfiguration.buildCompass(CompassConfiguration.java:288)
at grails.plugin.searchable.internal.compass.spring.SearchableCompassFactoryBean.buildCompass(SearchableCompassFactoryBean.java:95)
at grails.plugin.searchable.internal.compass.spring.SearchableCompassFactoryBean.getObject(SearchableCompassFactoryBean.java:58)
at grails.plugin.searchable.internal.compass.spring.SearchableCompassFactoryBean.getObject(SearchableCompassFactoryBean.java:41)
... 5 more
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.analysis.Analyzer$TokenStreamComponents
... 17 more
It seems as if the org.apache.lucene.analysis.Analyzer class does not contain TokenStreamComponents in lucene 2.4.1 (which is a dependency of searchable 0.6.9). But as I wrote, it works fine on my development machine.
PS: On Linux the war file is built by hudson.
UPDATE:
On my dev machine it does not run as war either but run-app does. I have no clue why it tries to use a method that is not present when running as a war file.
Thanks for your help in advance.
SOLVED:
Unfortunately the solution was simple: I had the Jasper plugin installed as well and it loads lucene 4.5.1 as dependency.
By excluding it with
compile (":jasper:1.10.0") {
excludes 'org.apache.lucene:lucene-core:4.5.1'
excludes 'org.apache.lucene:lucene-analyzers-common:4.5.1'
excludes 'org.apache.lucene:lucene-queryparser:4.5.1'
}
everything works as expected.

SLF4J exception when deploying to weblogic

We've started getting the following exception when deploying to Weblogic:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'alertService': Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailService': Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailMessageBuilderFactory': Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailMessageContentRenderer': Initialization of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'groovyPagesTemplateEngine': Cannot resolve reference to bean 'gspTagLibraryLookup' while setting bean property 'tagLibraryLookup'; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'gspTagLibraryLookup': Invocation of init method failed; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'grails.plugin.springsecurity.SecurityTagLib': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webInvocationPrivilegeEvaluator': Cannot resolve reference to bean 'filterInvocationInterceptor' while setting constructor argument; nested exception is
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'filterInvocationInterceptor': Invocation of init method failed; nested exception is
java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;
[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
I've tried removing the slf4j jar from my ear. I've also tried putting the following in my weblogic-appliction.xml:
<prefer-application-packages>
<package-name>org.slf4j.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>org/slf4j/impl/StaticLoggerBinder.class</resource-name>
</prefer-application-resources>
Nothing has worked thus far. Basically, I've tried all of the different things that I've found online. Usually, when I have a conflict with a jar that I'm providing myself and that Weblogic is also providing, just using the prefer-application-packages does the trick.
I'm using Grails 2.3.6 with Weblogic 10.3.6.
In case anyone comes across this issue, this is what my problem ended up being:
What was happening is that we were including the activemq-all artifact for JMS stuff, and this artifact is what they call an "uber" jar. It as a ton of dependencies baked into it that cannot be excluded via maven – one of those dependencies was an old version of slf4j. So, even though I had the "prefer-application-packages" set in Weblogic for slf4j, it wasn't using the Grails provided version, but rather the activemq one. Rather than using the activemq-all dependency, I switched to use individual components from activemq and was able to at that point exclude slf4j. This solved my issue.

Resources