My favorites | Sign in
Project Home Downloads Wiki Issues Source
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 1240: Spring JPA support unusable due missing javax.naming.NamingException
36 people starred this issue and may be notified of changes. Back to list
 
Reported by mcaslavsky@gmail.com, Apr 9, 2009
Some classes in Spring JPA support (spring-orm) references
javax.naming.NamingException (eg:
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor
catches NamingException), but javax.naming.NamingException is not
aviable in GAE (and is not whitelisted). 

org.springframework.beans.factory.BeanCreationException: Error creating
bean with name
'org.springframework.context.annotation.internalPersistenceAnnotationProcessor':
Initialization of bean failed; nested exception is
java.lang.NoClassDefFoundError: javax/naming/NamingException
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
	at java.security.AccessController.doPrivileged(Native Method)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
	at
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
	at
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
	at
org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:578)
	at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:365)
	at
org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
	at
org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
	at
org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
	at
org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:530)
	at org.mortbay.jetty.servlet.Context.startContext(Context.java:135)
	at
org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1218)
	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:500)
	at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
	at
com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:190)
	at
com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:167)
	at
com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:113)
	at
com.google.apphosting.runtime.JavaRuntime.handleRequest(JavaRuntime.java:235)
	at
com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:4547)
	at
com.google.apphosting.base.RuntimePb$EvaluationRuntime$6.handleBlockingRequest(RuntimePb.java:4545)
	at
com.google.net.rpc.impl.BlockingApplicationHandler.handleRequest(BlockingApplicationHandler.java:24)
	at com.google.net.rpc.impl.RpcUtil.runRpcInApplication(RpcUtil.java:359)
	at com.google.net.rpc.impl.Server$2.run(Server.java:792)
	at
com.google.tracing.LocalTraceSpanRunnable.run(LocalTraceSpanRunnable.java:56)
	at
com.google.tracing.LocalTraceSpanBuilder.internalContinueSpan(LocalTraceSpanBuilder.java:489)
	at com.google.net.rpc.impl.Server.startRpc(Server.java:748)
	at com.google.net.rpc.impl.Server.processRequest(Server.java:340)
	at
com.google.net.rpc.impl.ServerConnection.messageReceived(ServerConnection.java:422)
	at com.google.net.rpc.impl.RpcConnection.parseMessages(RpcConnection.java:319)
	at com.google.net.rpc.impl.RpcConnection.dataReceived(RpcConnection.java:290)
	at com.google.net.async.Connection.handleReadEvent(Connection.java:419)
	at
com.google.net.async.EventDispatcher.processNetworkEvents(EventDispatcher.java:733)
	at com.google.net.async.EventDispatcher.internalLoop(EventDispatcher.java:207)
	at com.google.net.async.EventDispatcher.loop(EventDispatcher.java:101)
	at com.google.net.rpc.RpcService.runUntilServerShutdown(RpcService.java:249)
	at
com.google.apphosting.runtime.JavaRuntime$RpcRunnable.run(JavaRuntime.java:373)
	at java.lang.Thread.run(Unknown Source)

Apr 17, 2009
#1 mailtopu...@gmail.com
I am using annotation based Spring MVC for appengine webapp and i get the same
exception when i deploy the application. Not sure how long this thing will take to
resolve.. or what's the other options??

May 1, 2009
#2 marko.as...@gmail.com
I'm having the same problem with Spring MVC. I'm not using JPA.
May 3, 2009
#3 chris22b...@googlemail.com
Hello,

I'm have the same problem with Spring MVC Annotations.
Here me applicationContext:

<bean
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
<context:component-scan base-package="de.example.web.servlet" />

Here the Spring MVC Servlet with Annotations

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;


@Controller
@RequestMapping("/index")
public class Home {

	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView index(HttpServletRequest request) {
		ModelAndView mav = new ModelAndView("index");
		mav.addObject("test", "Hello World!");

		return mav;
	}

}
log.log
20.7 KB   View   Download
May 3, 2009
#4 chris22b...@googlemail.com
If you will use the Spring MVC with Annotations then to apply Spring 3.0.
It works fine.

http://www.ardentlord.com/apps/blog/show/829881-spring-3-0-on-google-app-engine
Jun 13, 2009
#5 hell...@gmail.com
Hi,


I just ported an existing Spring (2.5.6) Web MVC/JPA app to Google App Engine, but it took me a couple of hours to get it running. At the end, I was confronted with two things causing Security exceptions when running 
the app on GAE:

1) Using something somewhere in Spring JPA
2) Using Spring form tags (if anybody wants a fix for this one, let me know)


The following source and bean config got rid my "...'org.springframework.context.annotation.internalPersistenceAnnotationProcessor': Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: 
javax/naming/NamingException..."


Java source:

package com.bsdroot.todo.web.gae.fixes;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * GAE: Spring JPA: Needed to get around the "java.lang.NoClassDefFoundError: 
 * javax/naming/NamingException" blacklisting problem.
 * 
 * Just register this dummy impl as bean with id: org.springframework.context.annotation.internalPersistenceAnnotationProcessor
 * 
 * @author robert
 * 
 */
public class GaeFixInternalPersistenceAnnotationProcessor {

  private static final Logger log = LoggerFactory
      .getLogger(GaeFixInternalPersistenceAnnotationProcessor.class);

  public GaeFixInternalPersistenceAnnotationProcessor() {
    log
        .info("Creating fake internalPersistenceAnnotationProcessor to bypass GAE blacklist problem");

  }

}


Spring config:
(I load this one using the org.springframework.web.context.ContextLoaderListener)

<beans>
 
 <bean id="org.springframework.context.annotation.internalPersistenceAnnotationProcessor" 
  class="com.bsdroot.todo.web.gae.fixes.GaeFixInternalPersistenceAnnotationProcessor" />

</beans>


HTH

gr,

--Robert
Jun 13, 2009
#6 tony.tom...@gmail.com
Many thanks, this fix worked for me.
Jun 26, 2009
#7 hongyan....@accenture.com
I tried the fix, but still getting the error while executing a webflow action.  Any 
help is appreciated.
Jun 29, 2009
#8 mailtopu...@gmail.com
for some reason it worked for me after i added few jars like annotation-api.jar
i am using spring MVC.
Jul 4, 2009
#9 br...@wasdrunk.com
I'm using absolutely no persistence at all. That's right.  No jpa. No jdo. Nothing.

Just a simple spring mvc (2.5.6) app with a single controller that spits out hello
world, and guess what? Exactly. Don't believe me? Try it!

This issue is misnamed, and the finger shouldn't be pointed at JPA.
Jul 15, 2009
#10 jirunga...@gmail.com
Im running an app with Spring 2.5.6 using JDO, this is not just a JPA problem. the fix 
poste by hellwig didnt work. 
Aug 14, 2009
#12 mcaslavsky@gmail.com
This bug applies to Spring 2.5.x, Spring 3.0.0.x seems to work.

One workaround for Spring 2.5.x si to use modified
org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor
and org.springframework.jndi.JndiLocatorSupport with
javax.naming.NamingException replacetd to java.lang.Exception
Jan 29, 2010
#15 tran.vch...@gmail.com
thanks, the fix work for me too.
Feb 8, 2010
#16 saee...@gmail.com
This helped. Thank you.
Apr 7, 2010
#17 jasonaco...@google.com
(No comment was entered for this change.)
Owner: jasonaco...@google.com
Apr 7, 2010
#18 jasonaco...@google.com
(No comment was entered for this change.)
Status: Accepted
Labels: -Type-Defect Type-Enhancement log-2577697
Jul 27, 2010
#19 adam.sch...@gmail.com
You don't have to remove spring-orm.jar to fix the issue, but you cannot use a proxy factory for transactions.  I removed this line and it worked.

    <bean id="persistenceManagerProxy" class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy">
        <property name="targetPersistenceManagerFactory" ref="persistenceManagerFactory" />
    </bean>
Dec 16, 2010
#20 i...@google.com
(No comment was entered for this change.)
Owner: i...@google.com
Dec 29, 2010
#21 gr...@google.com
(No comment was entered for this change.)
Labels: Component-ThirdParty
Feb 20, 2011
#22 schol...@gmail.com
this is is sure in spring2.5.6,
now i update my GAE ,use spring3.0.5,is worked!
Oct 17, 2011
#23 pa...@kryl.eu
I have found a fix for this problem for Spring 3.0.5 + JDO. The problem was again java.lang.ClassNotFoundException: javax.naming.NamingException.

Proper wiring of persistence manager + proxy + transaction manager is as follows:

    <bean id="persistenceManagerFactory" class="org.springframework.orm.jdo.LocalPersistenceManagerFactoryBean">
        <property name="persistenceManagerFactoryName" value="transactions-optional" />
    </bean>

    <bean id="persistenceManagerFactoryProxy" class="org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy">
        <property name="targetPersistenceManagerFactory" ref="persistenceManagerFactory" />
        <property name="allowCreate" value="false" />
    </bean>
    
    <bean id="transactionManager" class="org.springframework.orm.jdo.JdoTransactionManager">
        <property name="persistenceManagerFactory" ref="persistenceManagerFactory" />
    </bean>


I have found that during instantiation of org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy in setter setTargetPersistenceManagerFactory() spring tries to instantiate a class org.datanucleus.store.appengine.jdo.DatastoreJDOPersistenceManagerFactory (which is a mystery for me...). However this class implements 3 interfaces:
1. javax.jdo.PersistenceManagerFactory
2. javax.naming.spi.ObjectFactory
3. javax.naming.Referenceable

Nevertheless the last two interface are not permitted by appengine runtime. Therefore I reduce the implemented interfaces to contain just the first one. The fix looks as follows (patch org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy)

    /**
     * Set the target JDO PersistenceManagerFactory that this proxy should
     * delegate to. This should be the raw PersistenceManagerFactory, as
     * accessed by JdoTransactionManager.
     * @see org.springframework.orm.jdo.JdoTransactionManager
     */
    public void setTargetPersistenceManagerFactory(PersistenceManagerFactory target) {
        Assert.notNull(target, "Target PersistenceManagerFactory must not be null");
        this.target = target;
        // hack: javax.naming.* classes not permitted by app-engine
        // iface[0]: javax.jdo.PersistenceManagerFactory
        // iface[1]: javax.naming.spi.ObjectFactory
        // iface[2]: javax.naming.Referenceable
        // keep just iface[0]
        Class[] ifcs = ClassUtils.getAllInterfacesForClass(target.getClass(), target.getClass().getClassLoader());
        Class[] _ifcs = new Class[] { ifcs[0] };
            // we MUST NOT touch ifcs[1] nor ifcs[2] - they are javax.naming
        this.proxy = (PersistenceManagerFactory) Proxy.newProxyInstance(
                target.getClass().getClassLoader(), _ifcs, new PersistenceManagerFactoryInvocationHandler());
    }



Mar 6, 2012
#24 e...@ogenvik.org
Building on solution #23, I opted to fix it by extending TransactionAwarePersistenceManagerFactoryProxy with my own class, where I've overridden the default behaviour. This works well if you don't have the option of patching and rolling your own Spring.
Code then looks like this:

package org.springframework.orm.jdo;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import javax.jdo.PersistenceManagerFactory;
import org.springframework.util.ClassUtils;

public class GAETransactionAwarePersistenceManagerFactoryProxy extends TransactionAwarePersistenceManagerFactoryProxy {

    @Override
    public void setTargetPersistenceManagerFactory(PersistenceManagerFactory target) {
        try {
            // Set the "target" field. Which is private. So we need some dirty reflection.
            Field targetField = TransactionAwarePersistenceManagerFactoryProxy.class.getDeclaredField("target");
            targetField.setAccessible(true);
            targetField.set(this, target);

            // hack: javax.naming.* classes not permitted by app-engine
            // iface[0]: javax.jdo.PersistenceManagerFactory
            // iface[1]: javax.naming.spi.ObjectFactory
            // iface[2]: javax.naming.Referenceable
            // keep just iface[0]
            Class<?>[] ifcs = ClassUtils.getAllInterfacesForClass(target.getClass(), target.getClass().getClassLoader());
            Class<?>[] _ifcs = new Class[] { ifcs[0] };

            // Reflection needed since PersistenceManagerFactoryInvocationHandler is a private inner
            // class.
            @SuppressWarnings("unchecked")
            Class<? extends InvocationHandler> clazz = (Class<? extends InvocationHandler>) getClass().getClassLoader().loadClass("org.springframework.orm.jdo.TransactionAwarePersistenceManagerFactoryProxy$PersistenceManagerFactoryInvocationHandler");
            Constructor<? extends InvocationHandler> constructor = clazz.getDeclaredConstructor(TransactionAwarePersistenceManagerFactoryProxy.class);
            constructor.setAccessible(true);

            InvocationHandler invocationHandler = constructor.newInstance(this);
            PersistenceManagerFactory proxy = (PersistenceManagerFactory) Proxy.newProxyInstance(target.getClass().getClassLoader(), _ifcs, invocationHandler);
            // Set the "proxy" field. Which is private. So we need some dirty reflection.
            Field proxyField = TransactionAwarePersistenceManagerFactoryProxy.class.getDeclaredField("proxy");
            proxyField.setAccessible(true);
            proxyField.set(this, proxy);
        } catch (Exception e) {
            throw new RuntimeException("Error when trying to workaround issue with GAE and Spring 3.1. You might get this if you've upgraded Spring (since the reflection being done makes a lot of assumptions about the inner workings of Spring JDO).", e);
        }
    }
}

Jan 10, 2013
#25 sachin1...@gmail.com
Many Thanks .. Solution #24 is clean and works for me.
May 6, 2013
#26 Litvino...@gmail.com
#24 Thanks for solution
Sign in to add a comment

Powered by Google Project Hosting