//配置类
@Configuration
@ComponentScan(basePackages = "com.yinhai.fwtxgl.test1")
public class SysConfig {
@Bean("testService")
public TestService testService(){
System.out.println("配置类@bean给容器中添加组件了");
return new TestService();
}
//
@Component
@ConfigurationProperties(prefix = "msg")
public class MsgProperties {
private String SIGN ;
/*接口地址*/
private String URL;
/*接口账号*/
private String LOGIN_NAME ;
/*密码 */
private String PWD ;
/*计费套餐类型 */
private String FEE_TYPE ;
/**
* 是否真的发送短信
*/
private String MSG_TRUE_SEND ;
public String getSIGN() {
return SIGN;
}
public void setSIGN(String SIGN) {
this.SIGN = SIGN;
}
public String getURL() {
return URL;
}
public void setURL(String URL) {
this.URL = URL;
}
public String getLoginName() {
return LOGIN_NAME;
}
public void setLoginName(String loginName) {
LOGIN_NAME = loginName;
}
public String getPWD() {
return PWD;
}
public void setPWD(String PWD) {
this.PWD = PWD;
}
public String getFeeType() {
return FEE_TYPE;
}
public void setFeeType(String feeType) {
FEE_TYPE = feeType;
}
public String getMsgTrueSend() {
return MSG_TRUE_SEND;
}
public void setMsgTrueSend(String msgTrueSend) {
MSG_TRUE_SEND = msgTrueSend;
}
}
//测试类
@RunWith(SpringRunner.class)
@SpringBootTest
public class ConfigTest {
@Autowired
private MsgProperties msgProperties;
@Test
public void fun(){
System.out.println(msgProperties.getFeeType()+"888");
ApplicationContext context = new AnnotationConfigApplicationContext(SysConfig.class);
TestService helloService = (TestService) context.getBean("testService");
System.out.println(helloService);
boolean flag = context.containsBean("testService");
System.out.println("bean是否存在:" + flag);
}
}
最后
以上就是背后白猫最近收集整理的关于springboot单元测试配置类的全部内容,更多相关springboot单元测试配置类内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复