2012-03-20 123 views
1

工作,我敢肯定,我的應用程序的工作權利,直到昨天,當我得到這個錯誤:彈簧自動裝配停在GAE

Failed startup of context [email protected]1079ff{/,/ base/data/home/apps/s~trewnewmedia/1.357617962256387950} 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 it.trew.prove.web.controllers.ScadenziarioController.setScadenzaService(it. 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 it.trew.prove.services.ScadenzaService.setSocietaService(it.trew.prove.serv 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 it.trew.prove.services.SocietaService.setSocietaDao(it.trew.prove.model.dao .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 org.hibernate.impl.SessionFactoryImpl

我使用與谷歌雲SQL冬眠,它總是工作。

在我的本地機器上,使用本地MySQL,它仍然有效!

我不認爲這是一個雲SQL問題,因爲刪除一些自動裝配(測試)它仍然連接等。這裏是我的xml:

<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> 
     <property name="dataSource" ref="myDataSource" /> 
     <property name="annotatedClasses"> 
      <list> 
       <value>it.trew.prove.model.beans.Scadenza</value> 
       <value>it.trew.prove.model.beans.Fornitore</value> 
       <value>it.trew.prove.model.beans.Societa</value> 
      </list> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <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> --> 
      </props> 
     </property> 
    </bean> 

我的一塊DAO的:

@Component 
public class Dao { 

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

我的服務:

@Service 
@Transactional 
public class SocietaService { 

    private Dao societaDao; 

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

我找不到什麼是GAE和我的地方之間的不同(MVN GAE :跑)。 上週爲什麼完美運作。

請GAE團隊支持我!我對這個問題

快要瘋了(我可能會開始一個賞金,這太過分了急)

編輯我的pom.xml冬眠部分:

<!-- Hibernate framework --> 
    <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-core</artifactId> 
     <version>3.3.2.GA</version> 
     <type>pom</type> 
     <!--hibernate-dependencies is a pom, not needed for hibernate-core--> 
     </dependency> 
     <dependency> 
     <groupId>org.hibernate</groupId> 
     <artifactId>hibernate-annotations</artifactId> 
     <version>3.4.0.GA</version> 
    </dependency> 
    <dependency> 
     <groupId>javassist</groupId> 
     <artifactId>javassist</artifactId> 
     <version>3.12.1.GA</version> 
    </dependency> 
+0

的簽字同意核心問題是:'無法獲取org.hibernate.impl.SessionFactoryImpl類的成員是否需要更新Hibernate模塊? – vacuum 2012-03-20 10:18:11

+0

沒有...... :(見編輯 – 2012-03-20 12:00:19

+0

這個錯誤發生之前你做過的最後一次修改是什麼?如果它之前在工作,你必須做些什麼。 – 2012-03-21 10:29:49

回答

0

的問題是在@Service類@Transactional註釋。它在我不知道的某個部分使用javax.naming.NamingException,而這不是白名單的類。

3

似乎SessionFactoryImpl引用了一個谷歌沒有的白名單上的類,它不能在這種情況下加載。

下面是有關的文章:http://googlecloudsql.blogspot.de/

+0

等等?使用hibernate的解決方案是什麼? – 2012-03-23 07:55:23

+0

好像你不能像在獨立的情況下一樣使用ANY類以下是所有允許的類的列表:http://code.google.com/appengine/docs/java/jrewhitelist.html – 2012-03-23 09:20:44

+1

如果您的應用程序使用的是JPA,那麼我會簡單地使用不同的JPA提供程序。根本不可能在Google Cloud上使用Hibernate,但是我發現了一些關於某人實際上已經啓動並運行的文章...所以mabe這會有所幫助:http ://cloud.dzone.com/articles/spring-hibernate-google – 2012-03-23 09:23:52

1

法比奧幫助我指出了正確的方向。我發現使用@Transactional的聲明性事務在GAE中不起作用,因爲Spring掃描了org.hibernate.impl.SessionFactoryImpl,這會導致加載不在GAE白名單上的javax.naming類。我有同樣的問題切換到基於XML的聲明。所以我最終使用了使用TransactionTemplate對象的編程事務管理,並且似乎正在工作。

編輯:添加代碼示例

從我的春天配置我刪除<tx:annotation-driven/>禁用@Transactional與

<bean id="defaultTransactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> 
    <property name="transactionManager"><ref local="transactionManager"/></property> 
</bean> 

取代它,如果你正在使用多個事務語義如PROPAGATION_REQUIRED和PROPAGATION_SUPPORTS,您必須創建額外的bean,每個場景一個bean。

<bean id="supportingTransactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> 
    <property name="propagationBehaviorName" value="PROPAGATION_SUPPORTS"/> 
    <property name="transactionManager"><ref local="transactionManager"/></property> 
</bean> 

我用@Transactional表示法留下了我的原始服務類。這並不重要,因爲<tx:annotation-driven/>已被刪除,如果問題得到解決,我可能會在某一天切換回去。相反,我sublcassed他們使用TransactionTemplate的

public class GAEUserService extends UserService { 

    @Autowired 
    private TransactionTemplate defaultTransactionTemplate; 

    @Override 
    public void update(final User user) { 
     defaultTransactionTemplate.execute(new TransactionCallbackWithoutResult() { 
      @Override 
      protected void doInTransactionWithoutResult(TransactionStatus status) { 
       UserService.super.update(user); 
      } 
     }); 
    } 
} 

一個缺點我發現了,我不得不轉換檢查異常,由我服務的方法來unchecked異常拋出,因爲檢查的異常不doInTransactionWithoutResult

+0

我希望GAE團隊很快就會關注這一點,這非常重要。你可以發佈你使用的代碼嗎?舉個例子,謝謝 – 2012-04-28 17:02:40

+0

我更新了原文,包括一個代碼示例 – 2012-04-29 20:08:28