When my Grails WAR is hot-deployed to Tomcat and I refresh the page, I get this error:
1 Feb, 2010 7:00:51 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet view-servlet threw exception
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:15
This error does not persist when Tomcat is restarted.
ApplicationContext ctx = new ClassPathXmlApplicationContext();
Spring try to lookup the applicationContext.xml from the CLASSPATH, if the xml file can't be found, "BeanFactory not initialized or already closed" error will be thrown out. That is why you restart the tomcat it works just fine. However I don't know the real cause why the applicationContext.xml is not in the classpath during hot-deploy.
If you are running only one Grails application in your tomcat, you can try to put the applicationContext.xml in Tomcat classpath and try hot-deploy again.
Related
grails create-app example
grails war
deploying war to JBOSS 7.4 (failed to deployed see error below)
NOTE: tomcat -- works!
JBOSS deployed ERROR:
{"WFLYCTL0080: Failed services" => {"jboss.deployment.unit."grailsJboss7Point4Test-0.1.war".undertow-deployment" => "java.lang.RuntimeException: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [org.springframework.context.ConfigurableApplicationContext] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
Caused by: java.lang.RuntimeException: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [org.springframework.context.ConfigurableApplicationContext] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor).
Caused by: io.micronaut.context.exceptions.NoSuchBeanException: No bean of type [org.springframework.context.ConfigurableApplicationContext] exists. Make sure the bean is not disabled by bean requirements (enable trace logging for 'io.micronaut.context.condition' to check) and if the bean is enabled then ensure the class is declared a bean and annotation processing is enabled (for Java and Kotlin the 'micronaut-inject-java' dependency should be configured as an annotation processor)."}}
Tomcat 8.5.71
Grails 4.0.11
RHEL 7.8
The application runs fine with the embedded tomcat but won't load with standalone. Stacktrace is:
java.lang.IllegalStateException: Error starting child
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:757)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:727)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:695)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1016)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1903)
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.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/gdbxt]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753)
... 9 more
Caused by: java.lang.IllegalStateException: Already associated with parent BeanFactory: io.micronaut.spring.context.factory.MicronautBeanFactory#347aa4db: defining beans []; root of factory hierarchy
at org.springframework.beans.factory.support.AbstractBeanFactory.setParentBeanFactory(AbstractBeanFactory.java:718)
at org.springframework.context.support.GenericApplicationContext.setParent(GenericApplicationContext.java:158)
at org.springframework.boot.builder.ParentContextApplicationContextInitializer.initialize(ParentContextApplicationContextInitializer.java:58)
at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:623)
at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:367)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
at grails.boot.GrailsApp.run(GrailsApp.groovy:99)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:151)
at org.grails.boot.context.web.GrailsAppServletInitializer.createRootApplicationContext(GrailsAppServletInitializer.groovy:57)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:172)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5221)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 10 more
war file built for standalone tomcat has build.gradle with
provided "org.springframework.boot:spring-boot-starter-tomcat"
I have
server:
port: 8091
in application.yml and also have the connector set to 8091 in the tomcat server.xml
This app is ported from grails 2.5.5. and is quite large with a number of additional dependencies. It has quartz jobs which I disabled with quartz.pluginEnabled: false in application.yml.
It does get as far as running bootstrap.groovy since it prints out some logging from that code.
Can someone point me to a possible cause of this sort of error?
Turns out that I had created an extra package in the grails-app/init folder when migrating by creating a new grails 4 project and copying over the files from the grails2 project. The error was due to trying to instantiate a second Application from the Application.groovy in that second init folder. Surprising that it worked with the built in tomcat and run-app.
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!
I am getting the following exception when I am adding Hibernate jar to Struts2 with Tiles integrated web Application :
org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.apache.struts2.tiles.StrutsTilesListener
java.lang.NullPointerException
Getting above error when starting my struts application.
The following is the export order.
/WEB-INF/src
/WEB-INF/lib/freemarker-2.3.16.jar
/WEB-INF/lib/javassist-3.7.ga.jar
/WEB-INF/lib/ognl-3.0.jar
JRE System library[jrocket... ]
/WEB-INF/lib/commons-beanutils-1.8.0.jar
/WEB-INF/lib/commons-digester-1.8.1.jar
/WEB-INF/lib/commons-fileupload-1.2.1.jar
/WEB-INF/lib/commons-io-1.3.2.jar
/WEB-INF/lib/commons-logging-1.0.4.jar
/WEB-INF/lib/commons-logging-api-1.1.jar
/WEB-INF/lib/log4j-1.2.14.jar
/WEB-INF/lib/struts2-config-browser-plugin-2.2.1.jar
/WEB-INF/lib/struts2-core-2.2.1.jar
/WEB-INF/lib/struts2-tiles-plugin-2.2.1.jar
/WEB-INF/lib/tiles-api-2.1.2.jar
/WEB-INF/lib/tiles-compat-2.1.2.jar
/WEB-INF/lib/tiles-jsp-2.1.2.jar
/WEB-INF/lib/tiles-servlet-2.1.2.jar
/WEB-INF/lib/xwork-core-2.2.1.jar
weblogic/api.jar
json-2010.01.05.jar
/WEB-INF/lib/tiles-core-2.1.2.jar
Please help. I will be very happy
2014-06-30 13:51:39,448 INFO org.apache.tiles.context.AbstractTilesApplicationContextFactory.createFactory:72 - Initializing Tiles2 application context. . .
2014-06-30 13:51:39,458 INFO org.apache.tiles.context.AbstractTilesApplicationContextFactory.createFactory:91 - Finished initializing Tiles2 application context.
2014-06-30 13:51:39,480 INFO org.apache.tiles.factory.TilesContainerFactory.initializeContainer:362 - Initializing Tiles2 container. . .
(Ljava/lang/String;Ljava/lang/Throwable;)V not found.
java.lang.NoSuchMethodError: org.apache.tiles.TilesException: method (Ljava/lang/String;Ljava/lang/Throwable;)V not found
at org.apache.tiles.factory.NotAvailableFeatureException.(NotAvailableFeatureException.java:71)
at org.apache.tiles.portlet.context.NotAPortletEnvironmentException.(NotAPortletEnvironmentException.java:71)
at org.apache.tiles.portlet.context.PortletTilesRequestContextFactory.(PortletTilesRequestContextFactory.java:68)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
Truncated. see log file for complete stacktrace
2014-06-30 13:51:39,524 INFO org.apache.tiles.servlet.context.ServletUtil.setContainer:151 - Removing TilesContext for context: weblogic.servlet.internal.WebAppServletContext
<Jun 30, 2014 1:51:39 PM EDT> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID '1404150699134' for task '0'. Error is: 'weblogic.application.ModuleException: '
weblogic.application.ModuleException:
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1510)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:482)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodError: org.apache.tiles.TilesException: method <init>(Ljava/lang/String;Ljava/lang/Throwable;)V not found
at org.apache.tiles.factory.NotAvailableFeatureException.<init>(NotAvailableFeatureException.java:71)
at org.apache.tiles.portlet.context.NotAPortletEnvironmentException.<init>(NotAPortletEnvironmentException.java:71)
at org.apache.tiles.portlet.context.PortletTilesRequestContextFactory.<init>(PortletTilesRequestContextFactory.java:68)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
Truncated. see log file for complete stacktrace
<Jun 30, 2014 1:51:39 PM EDT> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 7 task for the application 'inhouse_brands'.>
<Jun 30, 2014 1:51:39 PM EDT> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating start task for application 'inhouse_brands'.>
<Jun 30, 2014 1:51:39 PM EDT> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException:
at weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1510)
at weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:482)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleStateDriver.java:425)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStateDriver.java:119)
Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodError: org.apache.tiles.TilesException: method <init>(Ljava/lang/String;Ljava/lang/Throwable;)V not found
at org.apache.tiles.factory.NotAvailableFeatureException.<init>(NotAvailableFeatureException.java:71)
at org.apache.tiles.portlet.context.NotAPortletEnvironmentException.<init>(NotAPortletEnvironmentException.java:71)
at org.apache.tiles.portlet.context.PortletTilesRequestContextFactory.<init>(PortletTilesRequestContextFactory.java:68)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
Truncated. see log file for complete stacktrace
Add this jars in your WEB-INF/lib folder
commons-lang3-3.1.jar
commons-lang-2.4.jar
slf4j-api-x.x.x.jar
slf4j-log4j12-x.x.x.jar
log4j-x.x.x.jar
Most importantly this jar is not in your project, So first download it and add it to your build path.
tiles-core.2.x.x.jar
tiles-template-2.x.x.jar
tiles-portlet-2.x.x.jar
You can choose version by yourself as per your project need.e.g. commons-lang-x.x,jar. Also reply if you get error.
And if you are new user to stack overflow then I will suggest you to learn how to accept answer Please see click HERE
EDIT :
Also I would like to tell you that struts2-tiles-plugin-2.2.1.jar depends on tiles 2.0.6 not tiles 2.2.1. Well, it does not matter. But it was just for your information. You should use proper version of tiles which should be compatible with your struts. At least try once using compatible versions.
What your error says is a resource could not be used because it is not in a portlet environment.
I will suggest you to Learn portlet integration of tiles
You are missing tiles-portlet-2.x.x.jar or portlet-ext.xml file
Edit 2:
Check rt.jar in your JRE.
If you don't have it on your classpath you will not have access to any of those classes you need to use like java.lang.String or java.io.File.