Netbeans中的春季示例应用程序 [英] spring sample application in netbeans

查看:131
本文介绍了Netbeans中的春季示例应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码.我有一些错误.谁能帮我解决问题?我遇到一些强制转换错误,例如将ClassPathResource强制转换为Resource,将资源对象r强制转换为资源.

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();

} 

}

这是我的XML文件;

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>

推荐答案

您正在使用javax.annotation.Resourceorg.springframework.core.io.Resource之类的资源,这导致了冲突.

You are using both the resources like javax.annotation.Resource and org.springframework.core.io.Resource, which has resulted in a conflict.

您需要像这样使用它们

org.springframework.core.io.Resource r = new ClassPathResource("applicationContext.xml");

然后程序将执行.

这篇关于Netbeans中的春季示例应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆