hibernate配置的原因?

在對HibernateDAO進行單元測試,一切運轉良好。單元測試代碼如下:

   private UserDAO userDAO = null;
    private User user = null;
    static {
        //通過Spring獲取類所在路徑
//        String pkg = ClassUtils.classPackageAsResourcePath(Constants.class);
        String[] paths = {"applicationContext-datasource.xml","applicationContext-hibernate.xml"};
        ctx = new ClassPathXmlApplicationContext(paths);
    }

    protected void setUp() throws Exception{
        super.setUp();
        userDAO = (UserDAO)ctx.getBean("userDAO");
    }

    public void testGetUser(){
        user = userDAO.getUser("test");
        System.out.println(user.getName());
    }

但是在Tomcat上運行就會報出如下錯誤,相信也有不少初學者也遇到如下的錯誤。不妨幫在下解答一下。


但是在Tomcat上運行就會報出如下錯誤,相信也有不少初學者也遇到如下的錯誤。不妨幫在下解答一下。


單元測試輸出結果如下:

[mywap] INFO [main] Environment.<clinit>(483) | Hibernate 2.1.8
[mywap] INFO [main] Environment.<clinit>(512) | hibernate.properties not found
[mywap] INFO [main] Environment.<clinit>(543) | using CGLIB reflection optimizer
[mywap] INFO [main] Environment.<clinit>(572) | using JDK 1.4 java.sql.Timestamp handling
[mywap] INFO [main] Binder.bindRootClass(229) | Mapping class: com.mywap.model.User -> User
[mywap] INFO [main] Configuration.secondPassCompile(641) | processing one-to-many association mappings
[mywap] INFO [main] Configuration.secondPassCompile(650) | processing one-to-one association property references
[mywap] INFO [main] Configuration.secondPassCompile(675) | processing foreign key constraints
[mywap] INFO [main] Dialect.<init>(86) | Using dialect: net.sf.hibernate.dialect.MySQLDialect
[mywap] INFO [main] SettingsFactory.buildSettings(67) | JDBC result set fetch size: 50
[mywap] INFO [main] SettingsFactory.buildSettings(70) | Maximim outer join fetch depth: 2
[mywap] INFO [main] SettingsFactory.buildSettings(74) | Use outer join fetching: true
[mywap] INFO [main] ConnectionProviderFactory.newConnectionProvider(53) | Initializing connection provider: org.springframework.orm.hibernate.LocalDataSourceConnectionProvider
[mywap] INFO [main] TransactionManagerLookupFactory.getTransactionManagerLookup(33) | No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
AbandonedObjectPool is used (org.apache.commons.dbcp.AbandonedObjectPool@1319c)
   LogAbandoned: false
   RemoveAbandoned: true
   RemoveAbandonedTimeout: 60000
[mywap] INFO [main] SettingsFactory.buildSettings(114) | Use scrollable result sets: true
[mywap] INFO [main] SettingsFactory.buildSettings(117) | Use JDBC3 getGeneratedKeys(): true
[mywap] INFO [main] SettingsFactory.buildSettings(120) | Optimize cache for minimal puts: false
[mywap] INFO [main] SettingsFactory.buildSettings(126) | echoing all SQL to stdout
[mywap] INFO [main] SettingsFactory.buildSettings(129) | Query language substitutions: {}
[mywap] INFO [main] SettingsFactory.buildSettings(140) | cache provider: net.sf.hibernate.cache.EhCacheProvider
[mywap] INFO [main] Configuration.configureCaches(1130) | instantiating and configuring caches
[mywap] WARN [main] Configurator.configure(126) | No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/F:/Ecws/AMWap/WEB-INF/lib/ehcache.jar!/ehcache-failsafe.xml
[mywap] INFO [main] SessionFactoryImpl.<init>(119) | building session factory
[mywap] INFO [main] SessionFactoryObjectFactory.addInstance(82) | Not binding factory to JNDI, no JNDI name configured
Hibernate: select user0_.name as name0_, user0_.passwd as passwd0_, user0_.email as email0_ from User user0_ where user0_.name=?
test

但是在Tomcat上運行就會報出如下錯誤,相信也有不少初學者也遇到如下的錯誤。不妨幫在下解答一下。


但是在Tomcat上運行就會報出如下錯誤,相信也有不少初學者也遇到如下的錯誤。不妨幫在下解答一下。


HTTP Status 500 -


type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'sessionFactory' must be of type [org.hibernate.SessionFactory], but was actually of type [net.sf.hibernate.impl.SessionFactoryImpl]
	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:242)
	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:151)
	org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:540)
	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:221)
	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.lookupSessionFactory(OpenSessionInViewFilter.java:205)
	org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:144)
	org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
	net.sf.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:167)
	net.sf.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:125)

note The full stack trace of the root cause is available in the Apache Tomcat/5.5.4 logs.


Apache Tomcat/5.5.4

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章