首页上一页 1 下一页尾页 1 条记录 1/1页
Failed to convert property value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource' 这个错误 怎么改啊
发表在Java图书答疑
2008-10-22
是否精华
是
否
版块置顶:
是
否
这是报错信息:
log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\Documents and Settings\Administrator\MyHibernate\springHibernate\src\applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1:[font color=#FF0000] org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource'[/font]
org.springframework.beans.PropertyAccessExceptionsException; nested PropertyAccessException details (1) are:
PropertyAccessException 1:
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource'
at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:949)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:690)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:570)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:735)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:762)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:751)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1065)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:863)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:382)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:277)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:321)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:89)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:74)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:65)
at Tester.main(Tester.java:12)
这是我的applicationContext.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/test"/>
<property name="username" value="root"/>
<property name="password" value="wsq"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<idref local="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>./Test.hbm.xml</value></list>
</property></bean></beans>
这是我的test.hbm.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="Test" table="mytest" catalog="test">
<id name="testId" type="java.lang.Integer">
<column name="test_id" />
<generator class="identity"></generator>
</id>
<property name="name" type="java.lang.String">
<column name="name" length="45" not-null="true" />
</property>
</class>
</hibernate-mapping>
这是我的javabean文件
// default package
/**
* Test generated by MyEclipse Persistence Tools
*/
public class Test implements java.io.Serializable {
// Fields
private Integer testId;
private String name;
// Constructors
/** default constructor */
public Test() {
}
/** full constructor */
public Test(String name) {
this.name = name;
}
// Property accessors
public Integer getTestId() {
return this.testId;
}
public void setTestId(Integer testId) {
this.testId = testId;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
这是我的测试文件:
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Tester {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
}
}
log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\Documents and Settings\Administrator\MyHibernate\springHibernate\src\applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1:[font color=#FF0000] org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource'[/font]
org.springframework.beans.PropertyAccessExceptionsException; nested PropertyAccessException details (1) are:
PropertyAccessException 1:
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource'
at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:949)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:690)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:570)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:735)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:762)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:751)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1065)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:863)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:382)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:234)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:144)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:277)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:321)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:89)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:74)
at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:65)
at Tester.main(Tester.java:12)
这是我的applicationContext.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/test"/>
<property name="username" value="root"/>
<property name="password" value="wsq"/>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<idref local="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>./Test.hbm.xml</value></list>
</property></bean></beans>
这是我的test.hbm.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="Test" table="mytest" catalog="test">
<id name="testId" type="java.lang.Integer">
<column name="test_id" />
<generator class="identity"></generator>
</id>
<property name="name" type="java.lang.String">
<column name="name" length="45" not-null="true" />
</property>
</class>
</hibernate-mapping>
这是我的javabean文件
// default package
/**
* Test generated by MyEclipse Persistence Tools
*/
public class Test implements java.io.Serializable {
// Fields
private Integer testId;
private String name;
// Constructors
/** default constructor */
public Test() {
}
/** full constructor */
public Test(String name) {
this.name = name;
}
// Property accessors
public Integer getTestId() {
return this.testId;
}
public void setTestId(Integer testId) {
this.testId = testId;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
这是我的测试文件:
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class Tester {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
}
}