spring autowiring stopped working on gae

spring autowiring stopped working on gae  using -'spring,hibernate,google-app-engine,autowired'

I'm sure my app worked right until yesterday, when I got this error:

  Failed startup of context
  org.springframework.beans.factory.BeanCreationException: Error
  creating bean with name 'scadenziarioController': Injection of
  autowired dependencies failed;  nested exception is
  org.springframework.beans.factory.BeanCreationException: Could not
  autowire method: public void
  trew.prove.services.ScadenzaService);  nested exception is
  org.springframework.beans.factory.BeanCreationException: Error
  creating bean with name 'scadenzaService': Injection of autowired
  dependencies failed;  nested exception is
  org.springframework.beans.factory.BeanCreationException: Could not
  autowire method: public void
  ices.SocietaService);  nested exception is
  org.springframework.beans.factory.BeanCreationException: Error
  creating bean with name 'societaService': Injection of autowired
  dependencies failed; nested exception is
  org.springframework.beans.factory.BeanCreationException: Could not
  autowire method: public void
  .Dao);  nested exception is
  org.springframework.beans.factory.BeanCreationException: Error
  creating bean with name 'dao': Injection of resource dependencies
  failed;  nested exception is
  org.springframework.beans.factory.BeanCreationException: Error
  creating bean with name 'mySessionFactory': Post-processing of the
  FactoryBean's object failed;  nested exception is
  java.lang.SecurityException: Unable to get members for class

I am using Hibernate with Google Cloud SQL, and it always worked.

On my local machine, with local MySQL, it still works!

I don't think it's a Cloud SQL issue, because removing some autowiring (a test) it still connects and so on. Here's my xml:

<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="dataSource" ref="myDataSource" />
        <property name="annotatedClasses">
        <property name="hibernateProperties">
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
                <!-- <prop key="hibernate.hbm2ddl.import_files">/setup.sql</prop> -->

A piece of my DAO:

public class Dao {

    @Resource(name = "mySessionFactory")
    private SessionFactory sessionFactory;

And my service:

public class SocietaService {

    private Dao societaDao;

    public void setSocietaDao(Dao societaDao) {
        this.societaDao = societaDao;

I can't find what's different between GAE and my local (mvn gae:run).
And why last week that worked perfectly.

Please GAE team, support me! I'm going crazy on this issue

(I'll probably start a bounty, it's too much urgent)

EDIT my pom.xml hibernate part:

<!-- Hibernate framework -->
        <!--hibernate-dependencies is a pom, not needed for hibernate-core-->


asked Oct 7, 2015 by dhananjayksharma
0 votes

3 Answers

0 votes

It seems that SessionFactoryImpl references a class that google doesn't have on it's whiteliste and it cant' be loaded in that case.

Here's an article about that: http://googlecloudsql.blogspot.de/

answered Oct 7, 2015 by vickeykumar66
0 votes

Fabio helped point me in the right direction. I found that declarative transactions using @Transactional do not work in GAE because Spring scans org.hibernate.impl.SessionFactoryImpl which causes the loading of javax.naming classes which are not on the GAE whitelist. I had the same issue switching to XML based declarations. So I ended up using programmatic transaction management using TransactionTemplate objects and that appears to be working.

EDIT: Added code sample

From my spring configuration I removed to disable @Transactional and replaced it with


If you're using multiple transaction semantics e.g. PROPAGATION_REQUIRED and PROPAGATION_SUPPORTS, you'll have to create additional beans, one for each scenario e.g.


I left my original service classes with the @Transactional notation. It doesn't matter since has been removed and I might switch back some day if the issue is fixed. Instead I sublcassed them to use TransactionTemplate

public class GAEUserService extends UserService {

    private TransactionTemplate defaultTransactionTemplate;

    public void update(final User user) {
        defaultTransactionTemplate.execute(new TransactionCallbackWithoutResult() {
            protected void doInTransactionWithoutResult(TransactionStatus status) {

The one downside I found was that I had to convert checked exceptions thrown by my service methods to unchecked exceptions because checked exceptions don't agree with the signature of doInTransactionWithoutResult

answered Oct 7, 2015 by jekbishnoi
0 votes

The problem is the @Transactional annotation on the @Service class. It uses javax.naming.NamingException in some part I don't know, and that's not a whitelisted class.

answered Oct 7, 2015 by deven.bendale