spring集成 hibernate应用后 运行测试类抱下面错误:javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial下面是我配置文件的片段!
<!-- 配置 SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 哪些方法参加事务 -->
<aop:config>
<aop:pointcut id="allmethod" expression="execution(* cn.orc.jie.spring.*.*(..))"/>
<aop:advisor advice-ref="txadvice" pointcut-ref="allmethod"/>
</aop:config>
<!-- 主应用事务类 -->
<bean id="userManager" class="cn.orc.jie.spring.UserManagerImp1">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>本人在线等待 有什么对问题不清楚的 提出来我在详细说明 谢谢大家了!!
<!-- 配置 SessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 配置事务的传播特性 -->
<tx:advice id="txadvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<!-- 哪些方法参加事务 -->
<aop:config>
<aop:pointcut id="allmethod" expression="execution(* cn.orc.jie.spring.*.*(..))"/>
<aop:advisor advice-ref="txadvice" pointcut-ref="allmethod"/>
</aop:config>
<!-- 主应用事务类 -->
<bean id="userManager" class="cn.orc.jie.spring.UserManagerImp1">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>本人在线等待 有什么对问题不清楚的 提出来我在详细说明 谢谢大家了!!
第一 我是java 项目 没有 web.xml
第二 我的包应该都引入了啊! 不管是spring 的还是 hibernate的
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>
<session-factory name="foo">
<property name="show_sql">true</property>
<property name="connection.username">root</property>
<property name="connection.url">jdbc:mysql://localhost:3306/spring_hibernate_test2</property>
<property name="connection.password">root</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="myeclipse.connection.profile">com.mysql.jdbc.Driver</property>
<property name="hbm2ddl.auto">update</property> <mapping resource="cn/orc/jie/hibernate/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>
改为
<session-factory name="sessionFactory">
或者去掉<session-factory name="foo">
那个只用在j2ee容器下或支持jndi动态绑定的容器。