sne*_*eha -1 java spring netbeans spring-mvc
这是我的代码。我得到了一些错误。谁能帮我解决问题?我收到了一些转换错误,比如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();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 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>
Run Code Online (Sandbox Code Playgroud)
小智 5
您正在使用两种资源,如javax.annotation.Resource和org.springframework.core.io.Resource,这导致冲突。
你需要像这样使用它们
org.springframework.core.io.Resource r = new ClassPathResource("applicationContext.xml");
Run Code Online (Sandbox Code Playgroud)
然后程序将执行。
| 归档时间: |
|
| 查看次数: |
3260 次 |
| 最近记录: |