3

项目名称:CarpoolDB,我已将此项目的 jar 添加到另一个应用程序名称 Carpool 中。在运行拼车应用程序时,我遇到了以下异常。

项目:拼车。在这里,我遇到异常,因为“carpoolService”在作为“Google Web 应用程序”运行时没有自动连接,但在 Tomcat 下运行相同,并且 bean 被正确注入。

@Controller
public class PlacesSearchController {

    @Autowired
    CarpoolService carpoolService=null;

    public CarpoolService getCarpoolService() {
        return carpoolService;
    }
    public void setCarpoolService(CarpoolService carpoolService) {
        this.carpoolService = carpoolService;
    }

} 

carpool-application-context1.xml

我还有 applicationContext-security.xml,用于弹簧安全性。

项目:CarpoolDB 所有类都在包中,com.company.carpooldb.db

    public interface CarpoolService {
        public boolean validateUser(User user);
    }

    @Service("carpoolService")
    public class CarpoolServiceImpl implements CarpoolService{

        @Autowired
        private CarpoolDao carpoolDao=null;

        public CarpoolDao getCarpoolDao() {
            return carpoolDao;
        }

        public void setCarpoolDao(CarpoolDao carpoolDao) {
            this.carpoolDao = carpoolDao;
        }

        @Override
        public boolean validateUser(User user) {
              return carpoolDao.validateUser(user);;
        }

    }


public interface CarpoolDao {
  public boolean validateUser(User user);
}

public class CarpoolDaoImpl extends HibernateDaoSupport implements CarpoolDao{
    @Override
    public boolean validateUser(User user) {
        // TODO Auto-generated method stub
        return false;
    }
}

拼车应用程序上下文.xml

<context:annotation-config />
        <context:component-scan base-package="com.onmobile" />
    <context:property-placeholder location="classpath:server.properties" />


    <bean id="sessionFactory" 

class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="mappingResources">
     <list>
            <value>com\company\carpooldb\hbm\User.hbm.xml</value>
     </list>   
     </property>
     <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect"><!--Which dialect is used of hibernate according to type of underlying database-->
                org.hibernate.dialect.MySQLDialect
            </prop>
            <prop key="hibernate.show_sql">false</prop>
        </props>
    </property>
    <property name="dataSource"><ref bean="dataSource"/></property> 

</bean>


<beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <beans:property name="driverClassName"><beans:value>${cm.db.driverClassName}</beans:value></beans:property>
    <beans:property name="url"><beans:value>${cm.db.url}</beans:value></beans:property>
    <beans:property name="username"><beans:value>${cm.db.username}</beans:value></beans:property>
    <beans:property name="password"><beans:value>${cm.db.password}</beans:value></beans:property>
    <beans:property name="testOnBorrow"><beans:value>true</beans:value></beans:property>
    <beans:property name="testOnReturn"><beans:value>true</beans:value></beans:property>
    <beans:property name="validationQuery"><beans:value>select 1</beans:value></beans:property>
</beans:bean>

    <!--Hibernate's transaction manager used for handling database transactions/manipulating data happening-->
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager" >
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>

    <bean id="carpoolDaoImpl" class="com.company.carpooldb.db.CarpoolDaoImpl">
        <property name="sessionFactory">
            <ref bean="sessionFactory" />
        </property>
    </bean>

在运行应用程序时,我遇到了异常,

log4j:WARN Error during default initialization
java.lang.NoClassDefFoundError: java.io.FileOutputStream is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
    at org.apache.log4j.FileAppender.setFile(FileAppender.java:290)
.........

    at com.google.appengine.tools.development.DevAppServerMain$StartAction.apply(DevAppServerMain.java:162)
    at com.google.appengine.tools.util.Parser$ParseResult.applyArgs(Parser.java:48)
    at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:113)
    at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)
log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j:WARN Please initialize the log4j system properly.
11 Nov, 2012 5:14:18 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: Failed startup of context com.google.apphosting.utils.jetty.DevAppEngineWebAppContext@5e55ab{/,D:\EclipseEuropa\CarpoolingGAE\war}
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'placesSearchController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.onmobile.carpooldb.db.CarpoolService com.onmobile.carpool.controller.PlacesSearchController.carpoolService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onmobile.carpooldb.db.CarpoolDao com.onmobile.carpooldb.db.CarpoolServiceImpl.carpoolDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
.........   
at com.google.appengine.tools.development.DevAppServerMain.<init>(DevAppServerMain.java:113)
    at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.onmobile.carpooldb.db.CarpoolService com.onmobile.carpool.controller.PlacesSearchController.carpoolService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onmobile.carpooldb.db.CarpoolDao com.onmobile.carpooldb.db.CarpoolServiceImpl.carpoolDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
    ... 31 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onmobile.carpooldb.db.CarpoolDao com.onmobile.carpooldb.db.CarpoolServiceImpl.carpoolDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
....    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:780)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    ... 33 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onmobile.carpooldb.db.CarpoolDao com.onmobile.carpooldb.db.CarpoolServiceImpl.carpoolDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
    ... 44 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
....    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    ... 46 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1412)
....    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
    ... 59 more
Caused by: java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
....    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1457)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1409)
    ... 66 more
11 Nov, 2012 5:14:18 PM com.google.apphosting.utils.jetty.JettyLogger warn
WARNING: Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'placesSearchController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.onmobile.carpooldb.db.CarpoolService com.onmobile.carpool.controller.PlacesSearchController.carpoolService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.onmobile.carpooldb.db.CarpoolDao com.onmobile.carpooldb.db.CarpoolServiceImpl.carpoolDao; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'carpoolDaoImpl' defined in class path resource [carpool-application-context.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [carpool-application-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google  App Engine developer's guide for more details.:
java.lang.NoClassDefFoundError: java.net.InetAddress is a restricted class. Please see the Google  App Engine developer's guide for more details.
    at com.google.appengine.tools.development.agent.runtime.Runtime.reject(Runtime.java:51)
    at org.hibernate.id.AbstractUUIDGenerator.<clinit>(AbstractUUIDGenerator.java:22)
    ......at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
.....
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:697)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1064)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
.....   at com.google.appengine.tools.development.DevAppServerMain.main(DevAppServerMain.java:89)
The server is running at http://localhost:8888/

为什么我得到 1. java.lang.NoClassDefFoundError: java.io.FileOutputStream 是一个受限类。

我没有在文件上写任何东西

  1. GAE 不支持我知道的少数 API,但我的应用程序已经在 MySQL 上工作,我想同时支持两者。我的意思是基于我的属性文件中设置的属性,我有时想使用 MySQL,有时想使用 GAE 数据存储。

我正在使用弹簧 3。

在这种情况下我应该怎么做?

4

1 回答 1

3

正如 Boris 所指出的,问题似乎与您的会话工厂有关。GAE 不支持 jdbc,而且看起来你的 sessionFactory 是为 mysql 配置的:

<property name="hibernateProperties">
    <props>
        <prop key="hibernate.dialect"><!--Which dialect is used of hibernate according to type of underlying database-->
            org.hibernate.dialect.MySQLDialect
        </prop>
        <prop key="hibernate.show_sql">false</prop>
    </props>
</property>

如果您正在使用依赖于 Hibernate 的现有代码库,您可以尝试将 Hibernate 配置为由 Cloud SQL 支持运行:https ://developers.google.com/appengine/articles/using_hibernate

至于 FileOutputStream 问题,我相信 log4j 的默认附加程序之一是 FileAppender,因此简单地不配置 log4j 不会解决它 - 您需要显式配置它。看看这个页面是否有帮助:http ://blog.xam.de/2010/03/logging-in-google-appengine-for-java.html

于 2012-11-29T19:00:33.763 回答