Commit a9800d93 authored by wutu's avatar wutu

starter化改造

parent 028a177e
...@@ -32,3 +32,6 @@ bs: ...@@ -32,3 +32,6 @@ bs:
port: 6653 port: 6653
zookeeper: zookeeper:
url: zk.cnf.org:2181 url: zk.cnf.org:2181
cnf:
passwd: Vudo3423
...@@ -20,9 +20,21 @@ ...@@ -20,9 +20,21 @@
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.springframework</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-context</artifactId> <artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
......
...@@ -2,6 +2,7 @@ package top.ninwoo.utils.config; ...@@ -2,6 +2,7 @@ package top.ninwoo.utils.config;
import com.spotify.docker.client.DefaultDockerClient; import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerClient; import com.spotify.docker.client.DockerClient;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -10,7 +11,8 @@ import java.net.URI; ...@@ -10,7 +11,8 @@ import java.net.URI;
@Configuration @Configuration
@ComponentScan("top.ninwoo.utils") @ComponentScan("top.ninwoo.utils")
public class DockerConfig { @EnableConfigurationProperties(UtilsProperties.class)
public class CNFUtilsAutoConfiguration {
@Bean(destroyMethod = "close") @Bean(destroyMethod = "close")
public DockerClient dockerClient() { public DockerClient dockerClient() {
return DefaultDockerClient.builder() return DefaultDockerClient.builder()
......
package top.ninwoo.utils.config;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "cnf.utils")
public class UtilsProperties {
private String passwd = "admin";
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
}
...@@ -3,6 +3,7 @@ package top.ninwoo.utils.util.impl; ...@@ -3,6 +3,7 @@ package top.ninwoo.utils.util.impl;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import top.ninwoo.utils.util.LinuxCtlUtils; import top.ninwoo.utils.util.LinuxCtlUtils;
import top.ninwoo.utils.util.OvsDockerUtils; import top.ninwoo.utils.util.OvsDockerUtils;
import top.ninwoo.utils.util.Utils; import top.ninwoo.utils.util.Utils;
...@@ -15,13 +16,17 @@ import top.ninwoo.utils.util.Utils; ...@@ -15,13 +16,17 @@ import top.ninwoo.utils.util.Utils;
@Utils @Utils
public class OvsDockerUtilsImpl implements OvsDockerUtils { public class OvsDockerUtilsImpl implements OvsDockerUtils {
private static Logger LOG = LoggerFactory.getLogger(OvsDockerUtilsImpl.class); private static Logger LOG = LoggerFactory.getLogger(OvsDockerUtilsImpl.class);
@Value("${cnf.passwd}")
private String passwd;
@Autowired @Autowired
LinuxCtlUtils linuxCtlUtils; LinuxCtlUtils linuxCtlUtils;
@Override @Override
public String addPort(String bridgeName, String devName, public String addPort(String bridgeName, String devName,
String containerId, String ip) { String containerId, String ip) {
String cmd = "ovs-docker add-port " + bridgeName String cmd = "echo '" + passwd + "' | sudo -S ovs-docker add-port " + bridgeName
+ " " + devName + " " + containerId + " --ipaddress=" + ip; + " " + devName + " " + containerId + " --ipaddress=" + ip;
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
if(res.contains("Error")) { if(res.contains("Error")) {
...@@ -37,7 +42,7 @@ public class OvsDockerUtilsImpl implements OvsDockerUtils { ...@@ -37,7 +42,7 @@ public class OvsDockerUtilsImpl implements OvsDockerUtils {
@Override @Override
public String delPort(String bridgeName, String devName, String containerId) { public String delPort(String bridgeName, String devName, String containerId) {
String cmd = "ovs-docker del-port " + bridgeName + " " String cmd = "echo '" + passwd + "' | sudo -S ovs-docker del-port " + bridgeName + " "
+ devName + " " + containerId; + devName + " " + containerId;
return linuxCtlUtils.runCmd(cmd); return linuxCtlUtils.runCmd(cmd);
......
...@@ -3,6 +3,7 @@ package top.ninwoo.utils.util.impl; ...@@ -3,6 +3,7 @@ package top.ninwoo.utils.util.impl;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import top.ninwoo.utils.entity.BridgePort; import top.ninwoo.utils.entity.BridgePort;
import top.ninwoo.utils.entity.Ovs; import top.ninwoo.utils.entity.Ovs;
import top.ninwoo.utils.entity.OvsBridge; import top.ninwoo.utils.entity.OvsBridge;
...@@ -26,11 +27,13 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -26,11 +27,13 @@ public class OvsUtilsImpl implements OvsUtils {
private final AtomicInteger atomicInteger = new AtomicInteger(0); private final AtomicInteger atomicInteger = new AtomicInteger(0);
@Autowired @Autowired
LinuxCtlUtils linuxCtlUtils; LinuxCtlUtils linuxCtlUtils;
@Value("${cnf.passwd}")
private String passwd;
@Override @Override
public boolean isInstall() { public boolean isInstall() {
// 可能会遇到权限问题 // 可能会遇到权限问题
String s = linuxCtlUtils.runCmd("ovs-vsctl --version"); String s = linuxCtlUtils.runCmd("echo '" + passwd + "' | sudo -S ovs-vsctl --version");
if(s.contains("Error")) { if(s.contains("Error")) {
return false; return false;
} else { } else {
...@@ -40,7 +43,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -40,7 +43,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override @Override
public Ovs showDetails() { public Ovs showDetails() {
String res = linuxCtlUtils.runCmd("ovs-vsctl show"); String res = linuxCtlUtils.runCmd("echo '" + passwd + "' | sudo -S ovs-vsctl show");
Ovs ovs = parseOvsString(res); Ovs ovs = parseOvsString(res);
return ovs; return ovs;
...@@ -128,7 +131,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -128,7 +131,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override @Override
public void addBridge(String name) { public void addBridge(String name) {
String cmd = "ovs-vsctl add-br " + name; String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl add-br " + name;
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
if(res.contains("Error")) { if(res.contains("Error")) {
throw new RuntimeException("linux bridge has existed!"); throw new RuntimeException("linux bridge has existed!");
...@@ -137,7 +140,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -137,7 +140,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override @Override
public void setBridgeProtocol(String bridgeName, String protocol) { public void setBridgeProtocol(String bridgeName, String protocol) {
String cmd = "ovs-vsctl set bridge " + bridgeName + " protocols=" + protocol; String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl set bridge " + bridgeName + " protocols=" + protocol;
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
if(res.contains("Error")) { if(res.contains("Error")) {
throw new RuntimeException(res); throw new RuntimeException(res);
...@@ -146,7 +149,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -146,7 +149,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override @Override
public void setController(String bridgeName, String host, int port) { public void setController(String bridgeName, String host, int port) {
String cmd = "ovs-vsctl set-controller " + bridgeName + " tcp:" + host + ":" + port; String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl set-controller " + bridgeName + " tcp:" + host + ":" + port;
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
if(res.contains("Error")) { if(res.contains("Error")) {
throw new RuntimeException(res); throw new RuntimeException(res);
...@@ -155,7 +158,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -155,7 +158,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override @Override
public void delBridge(String name) { public void delBridge(String name) {
String cmd = "ovs-vsctl del-br " + name; String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl del-br " + name;
LOG.info("删除网桥[{}]", name); LOG.info("删除网桥[{}]", name);
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
if(res.contains("Error")) { if(res.contains("Error")) {
...@@ -171,7 +174,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -171,7 +174,7 @@ public class OvsUtilsImpl implements OvsUtils {
*/ */
@Override @Override
public boolean addBridgePort(String bridgeName, String port) { public boolean addBridgePort(String bridgeName, String port) {
String cmd = "ovs-vsctl add-port " + bridgeName + " " + port; String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl add-port " + bridgeName + " " + port;
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
LOG.info("为Bridge:{} 添加Port:{}", bridgeName, port); LOG.info("为Bridge:{} 添加Port:{}", bridgeName, port);
if(!"".equals(res)) { if(!"".equals(res)) {
...@@ -183,7 +186,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -183,7 +186,7 @@ public class OvsUtilsImpl implements OvsUtils {
@Override @Override
public boolean delBridgePort(String bridgeName, String port) { public boolean delBridgePort(String bridgeName, String port) {
String cmd = "ovs-vsctl del-port " + bridgeName + " " + port; String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl del-port " + bridgeName + " " + port;
LOG.info("删除Bridge:{} Port:{}", bridgeName, port); LOG.info("删除Bridge:{} Port:{}", bridgeName, port);
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
if(!"".equals(res)) { if(!"".equals(res)) {
...@@ -203,7 +206,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -203,7 +206,7 @@ public class OvsUtilsImpl implements OvsUtils {
public String[] createVethPair(String br1, String br2) { public String[] createVethPair(String br1, String br2) {
String veth1 = br1 + "_" + br2; String veth1 = br1 + "_" + br2;
String veth2 = br2 + "_" + br1; String veth2 = br2 + "_" + br1;
String cmd = "ip link add " + veth1 + " type veth peer name " + veth2; String cmd = "echo '" + passwd + "' | sudo -S ip link add " + veth1 + " type veth peer name " + veth2;
LOG.info("创建虚拟网卡对[{},{}]", veth1, veth2); LOG.info("创建虚拟网卡对[{},{}]", veth1, veth2);
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
if(!"".equals(res)) { if(!"".equals(res)) {
...@@ -221,7 +224,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -221,7 +224,7 @@ public class OvsUtilsImpl implements OvsUtils {
public boolean delVethPort(String[] veths) { public boolean delVethPort(String[] veths) {
String veth1 = veths[0]; String veth1 = veths[0];
String veth2 = veths[1]; String veth2 = veths[1];
String cmd = "ip link del " + veth1 + " type veth peer name " + veth2; String cmd = "echo '" + passwd + "' | sudo -S ip link del " + veth1 + " type veth peer name " + veth2;
LOG.info("删除虚拟网卡对[{},{}]", veth1, veth2); LOG.info("删除虚拟网卡对[{},{}]", veth1, veth2);
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
if(!"".equals(res)) { if(!"".equals(res)) {
...@@ -239,7 +242,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -239,7 +242,7 @@ public class OvsUtilsImpl implements OvsUtils {
*/ */
@Override @Override
public boolean enableLinuxPort(String port) { public boolean enableLinuxPort(String port) {
String cmd = "ifconfig " + port + " up"; String cmd = "echo '" + passwd + "' | sudo -S ifconfig " + port + " up";
LOG.info("启动Linux端口:{}",port); LOG.info("启动Linux端口:{}",port);
String res = linuxCtlUtils.runCmd(cmd); String res = linuxCtlUtils.runCmd(cmd);
if(!"".equals(res)) { if(!"".equals(res)) {
...@@ -275,7 +278,7 @@ public class OvsUtilsImpl implements OvsUtils { ...@@ -275,7 +278,7 @@ public class OvsUtilsImpl implements OvsUtils {
public boolean setVxlan(String bridgeName, String remoteIp) { public boolean setVxlan(String bridgeName, String remoteIp) {
// TODO: bug // TODO: bug
int id = atomicInteger.getAndIncrement(); int id = atomicInteger.getAndIncrement();
String cmd = "ovs-vsctl add-port " + bridgeName String cmd = "echo '" + passwd + "' | sudo -S ovs-vsctl add-port " + bridgeName
+ " vxlan" + id + " -- set interface vxlan" + id + " type=vxlan options:remote_ip=" + remoteIp; + " vxlan" + id + " -- set interface vxlan" + id + " type=vxlan options:remote_ip=" + remoteIp;
System.out.println(cmd); System.out.println(cmd);
LOG.info("设置VXLAN[bridgeName:{},remoteIP:{},{}]", bridgeName, remoteIp,cmd); LOG.info("设置VXLAN[bridgeName:{},remoteIP:{},{}]", bridgeName, remoteIp,cmd);
......
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
top.ninwoo.utils.config.CNFUtilsAutoConfiguration
\ No newline at end of file
...@@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -7,7 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.common.entity.DockerContainer; import top.ninwoo.common.entity.DockerContainer;
import top.ninwoo.utils.config.DockerConfig; import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.service.DockerService; import top.ninwoo.utils.service.DockerService;
import top.ninwoo.utils.util.LinuxCtlUtils; import top.ninwoo.utils.util.LinuxCtlUtils;
...@@ -15,7 +15,7 @@ import java.util.ArrayList; ...@@ -15,7 +15,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class) @ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class DockerServiceTests { public class DockerServiceTests {
@Autowired @Autowired
private LinuxCtlUtils linuxCtlService; private LinuxCtlUtils linuxCtlService;
......
...@@ -7,7 +7,7 @@ import org.springframework.test.context.ContextConfiguration; ...@@ -7,7 +7,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import top.ninwoo.common.entity.DockerContainer; import top.ninwoo.common.entity.DockerContainer;
import top.ninwoo.utils.config.DockerConfig; import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.util.DockerUtils; import top.ninwoo.utils.util.DockerUtils;
/** /**
...@@ -16,7 +16,7 @@ import top.ninwoo.utils.util.DockerUtils; ...@@ -16,7 +16,7 @@ import top.ninwoo.utils.util.DockerUtils;
* @Date Create in 下午5:54 2019/10/25 * @Date Create in 下午5:54 2019/10/25
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class) @ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class DockerUtilsTest { public class DockerUtilsTest {
@Autowired @Autowired
DockerUtils dockerUtils; DockerUtils dockerUtils;
......
...@@ -4,7 +4,7 @@ import org.junit.runner.RunWith; ...@@ -4,7 +4,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.utils.config.DockerConfig; import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.service.IptablesService; import top.ninwoo.utils.service.IptablesService;
/** /**
...@@ -14,7 +14,7 @@ import top.ninwoo.utils.service.IptablesService; ...@@ -14,7 +14,7 @@ import top.ninwoo.utils.service.IptablesService;
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class) @ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class IptablesServiceTests { public class IptablesServiceTests {
@Autowired @Autowired
IptablesService iptablesService; IptablesService iptablesService;
......
...@@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -10,7 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.common.entity.DockerContainer; import top.ninwoo.common.entity.DockerContainer;
import top.ninwoo.utils.config.DockerConfig; import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.entity.ChainEntity; import top.ninwoo.utils.entity.ChainEntity;
import top.ninwoo.utils.entity.ChainType; import top.ninwoo.utils.entity.ChainType;
import top.ninwoo.utils.entity.TableType; import top.ninwoo.utils.entity.TableType;
...@@ -26,7 +26,7 @@ import java.util.Map; ...@@ -26,7 +26,7 @@ import java.util.Map;
* @Date Create in 上午11:54 2019/10/29 * @Date Create in 上午11:54 2019/10/29
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class) @ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class IptablesUtilsTests { public class IptablesUtilsTests {
private static final Logger LOG = LoggerFactory.getLogger(IptablesUtilsTests.class); private static final Logger LOG = LoggerFactory.getLogger(IptablesUtilsTests.class);
......
...@@ -6,11 +6,10 @@ import org.junit.runner.RunWith; ...@@ -6,11 +6,10 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.utils.config.DockerConfig; import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.entity.BridgePort; import top.ninwoo.utils.entity.BridgePort;
import top.ninwoo.utils.entity.Ovs; import top.ninwoo.utils.entity.Ovs;
import top.ninwoo.utils.entity.OvsBridge; import top.ninwoo.utils.entity.OvsBridge;
import top.ninwoo.utils.service.OVSService;
import top.ninwoo.utils.util.OvsUtils; import top.ninwoo.utils.util.OvsUtils;
...@@ -18,7 +17,7 @@ import java.util.ArrayList; ...@@ -18,7 +17,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class) @ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class OVSServiceTests { public class OVSServiceTests {
@Autowired @Autowired
private OvsUtils ovsService; private OvsUtils ovsService;
......
...@@ -5,7 +5,7 @@ import org.junit.runner.RunWith; ...@@ -5,7 +5,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.utils.config.DockerConfig; import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.util.OSUtils; import top.ninwoo.utils.util.OSUtils;
/** /**
...@@ -14,7 +14,7 @@ import top.ninwoo.utils.util.OSUtils; ...@@ -14,7 +14,7 @@ import top.ninwoo.utils.util.OSUtils;
* @Date Create in 上午10:45 2019/11/4 * @Date Create in 上午10:45 2019/11/4
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class) @ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class OsUtilsTests { public class OsUtilsTests {
@Autowired @Autowired
......
package top.ninwoo.utils; package top.ninwoo.utils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import top.ninwoo.utils.config.DockerConfig; import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
public class SpringMain { public class SpringMain {
public static void main(String[] args) { public static void main(String[] args) {
AnnotationConfigApplicationContext context = AnnotationConfigApplicationContext context =
new AnnotationConfigApplicationContext(DockerConfig.class); new AnnotationConfigApplicationContext(CNFUtilsAutoConfiguration.class);
} }
} }
...@@ -5,7 +5,7 @@ import org.junit.runner.RunWith; ...@@ -5,7 +5,7 @@ import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import top.ninwoo.utils.config.DockerConfig; import top.ninwoo.utils.config.CNFUtilsAutoConfiguration;
import top.ninwoo.utils.util.DockerUtils; import top.ninwoo.utils.util.DockerUtils;
/** /**
...@@ -14,7 +14,7 @@ import top.ninwoo.utils.util.DockerUtils; ...@@ -14,7 +14,7 @@ import top.ninwoo.utils.util.DockerUtils;
* @Date Create in 下午4:06 2019/10/30 * @Date Create in 下午4:06 2019/10/30
*/ */
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = DockerConfig.class) @ContextConfiguration(classes = CNFUtilsAutoConfiguration.class)
public class TcUtilsTests { public class TcUtilsTests {
@Autowired @Autowired
DockerUtils dockerUtils; DockerUtils dockerUtils;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment