Java Config 下的spring Test方式用了三种方式:1.纯手动取bean:package com.wang.test;import com.marsmother.commission.core.config.MapperCo
Java Config 下的spring Test方式
用了三种方式:
1.纯手动取bean:
package com.wang.test;import com.marsmother.commission.core.config.MapperConfig;import com.marsmother.commission.core.config.PropertyConfig;import com.marsmother.commission.core.config.ServiceConfig;import com.marsmother.commission.core.dto.GeneralResponseData;import com.marsmother.commission.core.service.UserService;import com.marsmother.commission.site.config.SecurityConfig;import org.junit.Before;import org.junit.Test;import org.springframework.context.annotation.AnnotationConfigApplicationContext;public class CustomeTest { private static AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); @Before public void tearUp(){ context.reGISter(PropertyConfig.class); context.register(ServiceConfig.class); context.register(SecurityConfig.class); context.register(MapperConfig.class); context.refresh(); } @Test public void testUser(){ UserService userService = context.getBean(UserService.class); Long userId = 3L; GeneralResponseData data = userService.addUserRelation(userId); System.out.println(data.getMsg()); }}
--结束END--
本文标题: Java Config下的Spring Test几种方式实例详解
本文链接: https://lsjlt.com/news/226571.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0