使用ssh编写了一web application ,正常运行。
在根包中建立一个类,编写public static void main(String args「」),
ApplicationContext ct=new ClassPathXmlApplicationContext("applicationContext.xml");产生异常,请问是什么原因,谢谢Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\Devcode\Workspaces\enjoyphoto\enjoyphoto\WebRoot\WEB-INF\applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
    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.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:423)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:140)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:84)
    at com.xgl.st.StartMain.main(StartMain.java:11)
Caused by: java.lang.reflect.MalformedParameterizedTypeException
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:42)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:35)
    at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:77)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:86)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:122)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
    at sun.reflect.generics.repository.ClassRepository.getSuperInterfaces(ClassRepository.java:82)
    at java.lang.Class.getGenericInterfaces(Class.java:794)
    at org.springframework.core.GenericTypeResolver.getTypeVariableMap(GenericTypeResolver.java:161)
    at org.springframework.core.GenericTypeResolver.resolveReturnType(GenericTypeResolver.java:99)
    at org.springframework.beans.GenericTypeAwarePropertyDescriptor.getPropertyType(GenericTypeAwarePropertyDescriptor.java:88)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
    ... 14 

解决方案 »

  1.   

    补充:在eclipse中右击类,以java application 运行
      

  2.   

    thread "main" org.springframework.beans.factory.BeanCreationException:sessionFactory 没创建
    你启动webServer了么
    他没有创建成功这个bean
      

  3.   

    sessionFactory创建失败  你看看你的xml文件中有没有配错啊
      

  4.   

    先谢谢了。如果启动webserver,用浏览器访问所有页面均正常。我的初衷是,不启动web server,编写client程序(swing)使用web project的包,利用spring+hibernate管理访问数据。也就是:由原来的:
    web--->struts2--->spring--->hibernate-->database.
    修改为:
    rich client app--->spring--->hibernate--->database.
      

  5.   

    <?xml version="1.0" encoding="UTF-8"?>
    <beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource"  destroy-method="close">
    <property name="driverClassName"
    value="com.mysql.jdbc.Driver">
    </property>
    <property name="url"
    value="jdbc:mysql://localhost:3306/enjoyphoto">
    </property>
    <property name="username" value="root"></property>
    <property name="password" value="888888"></property>
    </bean>
    <bean id="sessionFactory"
    class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource">
    <ref bean="dataSource" />
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">
    org.hibernate.dialect.MySQLDialect
    </prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    <property name="mappingResources">
    <list>
    <value>com/xgl/pojo/SysAppmoduleAccess.hbm.xml</value>
    <value>com/xgl/pojo/SysRole.hbm.xml</value>
    <value>com/xgl/pojo/TblComment.hbm.xml</value>
    <value>com/xgl/pojo/TblPhoto.hbm.xml</value>
    <value>com/xgl/pojo/TblPkg.hbm.xml</value>
    <value>com/xgl/pojo/TblUser.hbm.xml</value></list>
    </property></bean>
    <bean id="SysAppmoduleAccessDAO"
    class="com.xgl.dao.SysAppmoduleAccessDAO" scope="prototype">
    <property name="sessionFactory">
    <ref bean="sessionFactory"></ref>
    </property>
    </bean>
    <bean id="SysRoleDAO" class="com.xgl.dao.SysRoleDAO" scope="prototype">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="TblCommentDAO" class="com.xgl.dao.TblCommentDAO" scope="prototype">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="TblPhotoDAO" class="com.xgl.dao.TblPhotoDAO" scope="prototype">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="TblPkgDAO" class="com.xgl.dao.TblPkgDAO" scope="prototype">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>
    <bean id="TblUserDAO" class="com.xgl.dao.TblUserDAO" scope="prototype">
    <property name="sessionFactory">
    <ref bean="sessionFactory" />
    </property>
    </bean>


    <!-- service -->
    <bean id="ListPkgService" class="com.xgl.services.ListPkgService" scope="prototype">
    <property name="pkgDAO">
    <ref bean="TblPkgDAO" />
    </property>
    </bean>
    <bean id="ListPhotosService" class="com.xgl.services.ListPhotosService" scope="prototype">
    <property name="pkgDAO">
    <ref bean="TblPkgDAO" />
    </property>
    <property name="photoDAO">
    <ref bean="TblPhotoDAO" />
    </property>
    </bean>
    <bean id="ShowDetailsService" class="com.xgl.services.ShowDetailsService" scope="prototype">
    <property name="pkgDAO">
    <ref bean="TblPkgDAO" />
    </property>
    <property name="photoDAO">
    <ref bean="TblPhotoDAO" />
    </property>
    <property name="commentDAO">
    <ref bean="TblCommentDAO" />
    </property>
    </bean>
    <bean id="CommentService" class="com.xgl.services.CommentService" scope="prototype">
    <property name="commentDAO">
    <ref bean="TblCommentDAO" />
    </property>
    </bean>


    <!-- action -->
    <bean id="ListPkg" class="com.xgl.action.ListPkg" scope="prototype">
    <property name="listPkgService">
    <ref bean="ListPkgService" />
    </property>
    </bean>
    <bean id="ListPhotos" class="com.xgl.action.ListPhotos" scope="prototype">
    <property name="listPhotosService">
    <ref bean="ListPhotosService" />
    </property>
    </bean>
    <bean id="ShowDetails" class="com.xgl.action.ShowDetails" scope="prototype">
    <property name="listPhotosService">
    <ref bean="ListPhotosService" />
    </property>
    <property name="showDetailsService">
    <ref bean="ShowDetailsService" />
    </property>
    <property name="commentService">
    <ref bean="CommentService" />
    </property>
    </bean>
    <bean id="WriteComment" class="com.xgl.action.WriteComment" scope="prototype">
    <property name="commentService">
    <ref bean="CommentService" />
    </property>
    <property name="showDetailsService">
    <ref bean="ShowDetailsService" />
    </property>
    </bean>


    </beans>