spring整合Junit4

Maven依赖:

xml 复制代码
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13.2</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>5.3.18</version>
</dependency>

示例代码如下:

java 复制代码
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:applicationContext.xml"})
public class DemoTest {
    @Resource
    private ApplicationContext act;
    @Test
    public void fun(){
        Dept dept = (Dept) act.getBean("dept");
        System.out.println(dept);
    }
}
相关推荐
露天赏雪1 天前
第3篇:Sentinel熔断降级实战:大模型接口抖动时的服务兜底方案
java·开发语言·人工智能·spring boot·spring·servlet·sentinel
captain3761 天前
▲统一功能——DispatcherServlet源码分析
java·spring·java-ee·log4j·maven
TeamDev1 天前
使用 JxBrowser 在桌面应用中集成 Spring
java·前端·后端·spring·混合应用·jxbrowser·浏览器控件
SL_staff2 天前
从配置失效到逻辑复用:JVS-Logic 如何构建可治理的业务编排中枢
java·spring·产品
程序员吕洞宾2 天前
开源多维表格SmartTable v1.6.10 —— 用户名登录、数据评论及@人、表单分享二维码、性能优化、部署及升级优化
spring·性能优化·开源
liangbo72 天前
Spring系列03:Bean 的三种注册方式
java·spring
CoderYanger2 天前
Java EE 进阶:8.MyBatis 操作数据库(入门)(第一弹)
java·数据库·spring·面试·职场和发展·java-ee·mybatis
哦虎!2 天前
【JavaEE进阶】SpringIoC&DI
spring
敲代码的小小酥2 天前
谈SpringMVC与Spring WebFlux的区别与适用场景
java·后端·spring
风若飞3 天前
Spring Ai 入门遇到问题1
java·后端·spring