我导入了那个包结果的他的错误信息变了我只是想将Spring 和Hibernate整合到一起SpringTest cn.itcast.oa.test.SpringTest testSessionFactory(cn.itcast.oa.test.SpringTest) org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans. BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
SpringTest cn.itcast.oa.test.SpringTest testSessionFactory(cn.itcast.oa.test.SpringTest) org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'jdbcUrl' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Bean property 'jdbcUrl' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 唉毛病一个接一个的。求帮助啊
把代码发出来,帮忙看看吧 我写的测试文件package cn.itcast.oa.test;import org.hibernate.SessionFactory; import org.junit.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class SpringTest{
//测试SessionFactory @Test public void testSessionFactory() throws Exception{ ApplicationContext ac =new ClassPathXmlApplicationContext("applicationContext.xml"); SessionFactory sessionFactory= (SessionFactory) ac.getBean("sessionFactory"); System.out.println("--->" + sessionFactory);
cn.itcast.oa.test.SpringTest
testSessionFactory(cn.itcast.oa.test.SpringTest)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in
class path resource [applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.
BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]:
Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
cn.itcast.oa.test.SpringTest
testSessionFactory(cn.itcast.oa.test.SpringTest)
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory'
defined in class path resource [applicationContext.xml]: Error setting property values;
nested exception is org.springframework.beans.NotWritablePropertyException:
Invalid property 'jdbcUrl' of bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]:
Bean property 'jdbcUrl' is not writable or has an invalid setter method. Does the parameter type of the
setter match the return type of the getter?
唉毛病一个接一个的。求帮助啊
我写的测试文件package cn.itcast.oa.test;import org.hibernate.SessionFactory;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringTest{
//测试SessionFactory
@Test
public void testSessionFactory() throws Exception{
ApplicationContext ac =new ClassPathXmlApplicationContext("applicationContext.xml");
SessionFactory sessionFactory= (SessionFactory) ac.getBean("sessionFactory");
System.out.println("--->" + sessionFactory);
}
}
Spring的配置文件
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<!-- 自动扫描雨装配bean -->
<context:component-scan base-package="cn.itcast.oa"></context:component-scan>
<!-- 加载外部的配置文件 -->
<context:property-placeholder location="classpath:jdbc.properties"/>
<!--配置SessionFactory-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
<!--指定主配置文件的路径 -->
<property name="configLocation" value="hibernate.cfg.xml"></property>
<!--配置数据库连接池c3p0 -->
<property name="dataSource" >
<bean class="com.mchange.v2.c3p0.ComboPooledDataSource"></bean>
</property>
<!-- 数据库连接信息 -->
<property name="jdbcUrl" value="${jdbcUrl}"></property>
<property name="driverClass" value="${driverClass}"></property>
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<!-- 其他信息 -->
<!--初始化时获取三个连接,取值应在minPoolSize与maxPoolSize之间。Default: 3 -->
<property name="initialPoolSize" value="3"></property>
<!--连接池中保留的最小连接数。Default: 3 -->
<property name="minPoolSize" value="3"></property>
<!--连接池中保留的最大连接数。Default: 15 -->
<property name="maxPoolSize" value="5"></property>
<!--当连接池中的连接耗尽的时候c3p0一次同时获取的连接数。Default: 3 -->
<property name="acquireIncrement" value="3"></property>
<!-- 控制数据源内加载的PreparedStatements数量。如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0 -->
<property name="maxStatements" value="8"></property>
<!--maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。Default: 0 -->
<property name="maxStatementsPerConnection" value="5"></property>
<!--最大空闲时间,1800秒内未使用则连接被丢弃。若为0则永不丢弃。Default: 0 -->
<property name="maxIdleTime" value="1800"></property>
</bean>
<!-- 配置声明式事物管理,采用基于注解的方式 --></beans>