【发布时间】:2013-11-08 03:06:09
【问题描述】:
这是我的代码。我得到了一些错误。谁能帮我解决问题?我遇到了一些转换错误,例如将 ClassPathResource 转换为 Resource 并将资源对象 r 转换为资源。
package firstspring;
import javax.annotation.Resource;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class test {
public static void main(String[] args){
Resource r =new ClassPathResource("applicationContext.xml");
BeanFactory bf=new XmlBeanFactory(r);
Student stud=(Student)bf.getBean("first");
stud.display();
}
}
这是我的 XML 文件;
<?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: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">
<bean id="first" class="Student">
<property name="name" value="sneha"></property>
</bean>
</beans>
【问题讨论】:
-
它显示了一些错误所有这些错误是什么?
-
格式化您的问题,使其更具可读性。
-
@PradeepSimha 错误是将 classpathresorce 转换为 cast..
-
你在哪里声明了 eResource,或者它是一些内置类,如果是的话......你错过了导入。
-
eResource似乎是一个错字。应该是Resource。
标签: java spring spring-mvc netbeans