小编opa*_*pai的帖子

使用多个主类运行 spring boot

目前在我们的应用程序中,我们有多个主类,并分别使用以下命令单独执行它们。

java -Xmx1024M -cp /path/to/jar/MyApp.jar com.....MyAppMain1

java -Xmx1024M -cp /path/to/jar/MyApp.jar com.....MyAppMain2

java -Xmx1024M -cp /path/to/jar/MyApp.jar com.....MyAppMain3

现在尝试使用弹簧靴。我们该怎么做才能达到同样的目标?

在 pom.xml 中有

…….
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.8.RELEASE</version>
    </parent>

……..
Run Code Online (Sandbox Code Playgroud)

使用spring boot并执行命令

java -Xmx1024M -cp /path/to/jar/MyApp.jar com.....MyAppMain1

获取错误为 [ERROR] 无法在项目 MyApp 上执行目标 org.codehaus.mojo:exec-maven-plugin:1.6.0:java (default-cli):目标 org.codehaus.mojo:exec 的参数“mainClass” -maven-plugin:1.6.0:java 丢失或无效

spring-boot

6
推荐指数
1
解决办法
8329
查看次数

哪个更好,Java反射或扩展类测试

有一个Java类,我正在尝试编写一个JUnit测试.

使用JaCoCo监控代码覆盖率.因此,需要从测试类调用私有方法.

使用Java反射从测试类调用main方法和私有方法.

我的问题是更好地扩展测试类中的主类(示例)或使用java反射来访问私有方法?目前我正在使用如下反射.

在测试类中扩展Java类是一个好习惯吗?
因此,我是新编写测试类的问题.我很感激你的帮助.

public class Example { 
    public static void main(String[] s) {
        method1();
        method2();
        ..........
    }

    private Employee method1(String str) {
        .........
    }

    private Employee method2(String str1) {
        .........
    }
}

public class ExampleTest { 
    @InjectMocks
    Example example;
    .....

    @Before
    public void setUp() {
        ........
    }
    @Test
    public void testMain() {    
        try {
            String[] addresses = new String[]{};
            Example loadSpy = spy(example);
            loadSpy.main(addresses);            
            assertTrue(Boolean.TRUE);           
        } catch (.. e) {
            .......
        }
        assertTrue(true);
    }
    @Test
    public void …
Run Code Online (Sandbox Code Playgroud)

java junit4

2
推荐指数
1
解决办法
99
查看次数

标签 统计

java ×1

junit4 ×1

spring-boot ×1