ECM
ECM
总版主
总版主
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:469回复:0

spring sample application in netbeans

楼主#
更多 发布于:2016-05-12 14:42
This is my code. I have gotten some errors. Can anyone help me solve the problem? I get some casting errors, like cast ClassPathResource to Resource and resource object r to resource. 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();

}

}
 This is my XML file; <?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>You are using both the resources like javax.annotation.Resource and org.springframework.core.io.Resource, which has resulted in a conflict. You need to use them like this org.springframework.core.io.Resource r = new ClassPathResource("applicationContext.xml");
 then program will execute.

 

 

 

 

 

 

 

异常中心网是一家专门收集整理程序员编程过程中遇到的常见异常(exception)以及各种异常问答中心的网站。异常中心网旨在,减少程序员在编码遇到异常,处理各种异常时间和痛苦,让程序员能更愉快的、快速的定位异常并查找对应的异常解决方案。异常中心网诚心打造最完美的编程社区为程序员用户服务,努力成为最好的程序员乐园程序员社区程序异常中心程序bug中心异常问答中心

 

喜欢0 评分0
游客

返回顶部