在spring和hibernate进行整合时,JUnit调试时出现错误 :
Failed to load ApplicationContext
后查明原因,在applicationContext中写hibernate.cfg.xml相关配置信息时,key=“ ”中没有加入hibernate.这个前缀
以下为相关xml代码
<bean name="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<!--配置hibernate基本信息-->
<property name="hibernateProperties" >
<props>
<!--必选配置-->
<prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
<prop key="hibernate.connection.url">jdbc:mysql://localhost:3306/test?characterEncoding=UTF-8</prop>
<prop key="hibernate.connection.username">root</prop>
<prop key="hibernate.connection.password">admin</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<!--可选配置-->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!--引入orm元数据-->
<property name="mappingDirectoryLocations" value="classpath:entity"/>
</bean>