Receiving a Spring RequestMappingHandlerMapping error in Google App Engine - java

I have built a simple Spring MVC application that works flawlessly on my local machine. Having uploaded it to the Google App Engine, however, I receive a HTTP 500 error.
Looking into the logs I recieve this INFO message:
org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions: Loading XML bean definitions from ServletContext resource [/WEB-INF/enterprise-servlet.xml]
Which is normal, as I receive this INFO message when running the app locally. Spring would then go onto map urls onto methods, for example a log message from my local machine:
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping.register Mapped "{[/listStaff],methods=[GET],produces=[application/json || application/xml]}" onto public java.util.List<org.andrewvincent.model.Staff> org.andrewvincent.controller.Controller.listStaffXML()
However when looking at the logs from the app engine, I receive the following error:
org.springframework.web.context.support.XmlWebApplicationContext refresh: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping': Invocation of init method failed; nested exception is java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.reflect.annotation")
I assume this is why I am receiving the 500 error code, as the urls are not being mapped onto the methods, but I cannot work out why I receive this error when I don't locally.
The following is my enterprise-servlet.xml:
<beans xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven/>
<bean id="controllerBean" class="org.andrewvincent.controller.Controller"></bean>
<bean id="plainControllerBean"
class="org.andrewvincent.controller.PlainTextController"></bean>
<mvc:resources mapping="/resources/**" location="/resources/"/>
<mvc:default-servlet-handler/>
</beans>
If anyone could help me out it would be much appreciated.

This is a known bug.
Are you using 4.2.4? If so you should downgrade to 4.2.3.

Related

do not fail spring container if bean does not exist

I have 3 modules on project. One of them calls common. In this module i am trying to start Spring container. One of beans live in another module (webapp) and also i have a module testapp. So now, after deploying project on server (webapp and common) it is all OK, but if I try to deploy common and testapp it fails with exception:
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class[...]
i whant to know if it is any possibility to ignore unexisting bean and run container? I am using xml configuration, no annotations. Due to business logic it should be exactly xml
Make use of Spring profiles to determine when specific beans should be instantiated. For example you can have two profiles web (for common + webapp) and test (for common + testapp)
Then in your application context xml configuration define your beans as follows
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">
<!-- define common beans here-->
<beans profile="test">
<!-- define test beans here-->
</beans>
<beans profile="web">
<!-- define web beans here-->
</beans>
</beans>
Then depending on how you launch your application you need to provide a system property named spring.profiles.active to provide the profile to use.
For example -Dspring.profiles.active=web or -Dspring.profiles.active=test

appengine spring aop java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.reflect")

I am creating application with spring aspect but in app engine when I hit first request then exception occurs while initialize spring framework.
Exception stack trace is as below:
SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adminController' defined in file [PATH\PACKAGE\AdminController.class]:
Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException:
Unexpected AOP exception; nested exception is java.security.AccessControlException:
access denied ("java.lang.RuntimePermission" "accessClassInPackage.sun.reflect")
My Aspect
#Aspect
#Component
public class AuthorizationAspect {
#Around(value="#annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object interceptApplicationRequest(
ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
System.out.println("test");
return proceedingJoinPoint.proceed();
}
}
My Controller
#Controller
#RequestMapping(value="/admin")
public class AdminController {
#RequestMapping(value = "/add", method = RequestMethod.GET)
public ModelAndView add(){
ModelAndView mv = new ModelAndView("add");
return mv;
}
}
Configuration in XML
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">
<context:component-scan base-package="com.package.name" />
<aop:aspectj-autoproxy/>
<mvc:annotation-driven />
</beans>
Is AOP not allowed in app engine framework?
App Engine version: 1.9.7
Spring Framework: 4.0.3
Based on the exception message, it is likely that the library you are using relies on some classes that are not in the App Engine's White list: https://cloud.google.com/appengine/docs/java/jrewhitelist
In particular, I don't see any of sun.reflect* classes in this white list. Hence, you are getting AccessControllException.

java.lang.IllegalStateException: start tag has already been written wso2 as

I created a JAX-WS project wso2 developer studio.
In this project I inherited from interface DocumentRegistryPortType we can find in the lib developed by Rahul(http://repo1.maven.org/maven2/com/github/rahulsom/ihe-iti/0.7/ihe-iti-0.7.jar)!.
When I try to access the wsdl in the WSO2 AS shows me the following error.
[2014-05-19 01:15:46,943] INFO {org.apache.cxf.service.factory.ReflectionServiceFactoryBean} - Creating Service {urn:ihe:iti:xds-b:2007}DocumentRegistry_Service from class ihe.iti.xds_b._2007.DocumentRegistryPortType
[2014-05-19 01:15:51,080] INFO {org.springframework.beans.factory.support.DefaultSingletonBeanRegistry} - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory#6bc684d1: defining beans [cxf,org.apache.cxf.bus.spring.BusWiringBeanFactoryPostProcessor,org.apache.cxf.bus.spring.Jsr250BeanPostProcessor,org.apache.cxf.bus.spring.BusExtensionPostProcessor,DocumentRegistry]; root of factory hierarchy
[2014-05-19 01:15:51,081] ERROR {org.apache.catalina.core.ApplicationContext} - StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DocumentRegistry': Invocation of init method failed; nested exception is java.lang.IllegalStateException: start tag has already been written
Any idea what could be this error?
This is my cxf-servlet.xml file. The name of the package is jax and the class is DocumentRegistry. This class implement of DocumetRegistryPortType.
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:server id="DocumentRegistry" address="/servicio">
<jaxws:serviceBean>
<bean class="jax.DocumentRegistry"/>
</jaxws:serviceBean>
</jaxws:server>
</beans>

Spring XSD's access error

I'm trying to run a system left by an ex-employee here in my job, but I'm having problems to do it.
If the XSD runs by remote access:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
It gives an not found exception:
Failed to read schema document 'http://www.springframework.org/schema/context/spring-context-3.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
And if the XSD runs by local access:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
classpath:org/springframework/transaction/config/spring-tx-3.0.xsd
http://www.springframework.org/schema/context
classpath:org/springframework/context/config/spring-context-3.0.xsd
http://www.springframework.org/schema/tool
classpath:org/springframework/beans/factory/xml/spring-tool-3.0.xsd">
It gives this exception:
C:\Users\claudiomazur>java -jar c:\temp\fin\c.jar
0 [AWT-EventQueue-0] INFO support.ClassPathXmlApplicationContext - Refreshing org.springframework.context.support.ClassPathXmlApplicationContext#4fa52fdf: startup date [Thu Sep 06
11:22:59 BRT 2012]; root of context hierarchy
45 [AWT-EventQueue-0] INFO xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [context.xml]
Exception in thread "AWT-EventQueue-0" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for
XML schema namespace [http://www.springframework.org/schema/context]
Offending resource: class path resource [context.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
Some idea to solve this problem?
Big hug!!
The Spring XDSs are defined and shipped with the Spring jars! For Example the spring-context.jar contains the spring-context-3.0.xsd. (see spring-context.jar/META-INF/spring.schema)
So check that you have this jar in your project.
So what you called "remote" is not really remote! And I have never see what you called "local access", so I would try to check why the "remote" (that is not remote) stuff works for all xsds but the spring-context.
If it is a desktop program and you use a single jar that contains all the other exploded jars, then you need a to take care that the content of the single spring.handlers and spring.schames files from the different spring-xxx.jar is COMBINED in (two) "hunge" files. So that in the end this (two) files contains all the schema names and handler names.
Its true that the SPRING XSD's are shipped along with the jars.
The information where these XSD's are stored :
Lets say in the XML file, we have used beans namespace and we need to look into
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
Please check the file "spring-schemas" spring-beans-4.0.1.RELEASE.jar in META-INF folder.
Sample context from this file should be:
http\://www.springframework.org/schema/beans/spring-beans-4.0.xsd
=org/springframework/beans/factory/xml/spring-beans-4.0.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd
=org/springframework/beans/factory/xml/spring-beans-4.0.xsd
Thus
http\://www.springframework.org/schema/beans/spring-beans.xsd is mapped to
org/springframework/beans/factory/xml/spring-beans-4.0.xsd
in your jar
try run wget http://www.springframework.org/schema/context/spring-context-3.0.xsd.
should be something like: wget http://www.springframework.org/schema/context/spring-context-3.0.xsd
--2012-09-10 15:56:05-- http://www.springframework.org/schema/context/spring-context-3.0.xsd
Resolving www.springframework.org... 205.140.197.88
Connecting to www.springframework.org|205.140.197.88|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19651 (19K) [text/xml]
Saving to: “spring-context-3.0.xsd”
100%[=====================================================================>] 19,651 24.6K/s in 0.8s
2012-09-10 15:56:06 (24.6 KB/s) - “spring-context-3.0.xsd” saved [19651/19651]
If you have a problem with getting xsd schema, it makes difficult to work with xml files inherited this schema.
In second case you simply don't have in classpath any of spring-*-3.0.xsd files.

Spring XML schemas

I am noticing a strange issue with respect to spring XML schemas.
I have a standalone java application which uses spring framework. As long as I run this application within eclipse, I do not face any issues. However, when I package this as a jar file (as described in this link), and execute the jar, I get the following exception:
Exception in thread "main" org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/tx]
Offending resource: class path resource [applicationContext.xml]
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:316)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1416)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1409)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
I have the following entry in applicationContext.xml and it works fine inside eclipse:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
Any help is much appreciated.
I even tried changing http://www.springframework.org/schema/tx/spring-tx-3.1.xsd to classpath:/org/springframework/transaction/config/spring-tx-3.1.xsd but it did not help.
It looks like your application contains some jars, like spring-core-3.1.x (because its classes are being used), but it's missing spring-tx-3.1.x.RELEASE.jar (the one that holds Spring Transaction classes).

Categories