博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解决spring的xml文件cannot be open ( class path resource cannot be opened)
阅读量:3903 次
发布时间:2019-05-23

本文共 1227 字,大约阅读时间需要 4 分钟。

xml文件一直显示cannot be open

报错语句有一条:

class path resource [bean2.xml] cannot be opened because it does not exist
at(后面的没有复制了)

然后好像是xml没有被编译的原因?

设置了一个resourse mark as test resources root

在这里插入图片描述

现在目录如下:

在这里插入图片描述

然后问题解决了。
Userservice:

package com.spring.demo.service;import com.spring.demo.dao.UserDao;import com.spring.demo.dao.UserDaoimp;public class Userservice {
//创建userdao类属性 private UserDao userdao; public void setUserdao(UserDao userdao) {
this.userdao = userdao; } public void add() {
System.out.println("servicee add.."); } public void setUserDao(UserDaoimp userDao) {
this.userdao=userDao; }}

bean2.xml:

Testbean.java:

package com.spring.demo.test;import com.spring.demo.service.Userservice;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.testng.annotations.Test;public class Testbean {
@Test public void testAdd() {
ApplicationContext context = new ClassPathXmlApplicationContext("bean2.xml"); Userservice userservice = context.getBean("userservice", Userservice.class); userservice.add(); }}

run之后结果:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-O9bQGCaY-1611394339426)(C:\Users\14172\AppData\Roaming\Typora\typora-user-images\image-20210123132311671.png)]

转载地址:http://uvten.baihongyu.com/

你可能感兴趣的文章
486. 预测赢家
查看>>
494. 目标和
查看>>
520. 检测大写字母
查看>>
数据处理和训练模型的技巧
查看>>
vb 中如何做同步 异步?
查看>>
geturl
查看>>
李建忠,设计模式教程.笔记061220
查看>>
李建忠,设计模式教程.笔记061221
查看>>
关于sizeof
查看>>
windows 核心编程笔记.070301
查看>>
WINDOWS核心编程笔记 070303
查看>>
终于解决了交叉表左上角,每页都显示的问题.
查看>>
windows核心编程 070309
查看>>
哈,又解决水晶报表的一个难题
查看>>
VC Ini文件处理
查看>>
一直误解sql事务的用法.
查看>>
转:利用C#实现分布式数据库查询
查看>>
转:Remoting系列(三)----对象的生命周期管理
查看>>
转:Remoting系列(二)----建立第一个入门程序
查看>>
转:Remoting系列(一)----Remoting的基本概念
查看>>