我正在尝试确定一种方法来了解启动SpringBoot的Main-Class
的名称。例如
@SpringBootApplication
public class SampleApplication {
public static void main(String[] args) {
SpringApplication.run(SampleApplication.class, args);
}
@RestController
public class SampleController
{
@GetMapping("/hello")
pubic String sayHello()
{
System.out.println("Need start class name: "+System.getProperty("sun.java.command"));
return "hello";
}
}
}
当我使用java -jar myappname.jar
运行springboot时,System.getProperty("sun.java.command"(返回org.springframework.boot.loader.JarLauncher
有人能告诉我,我如何才能得到实际运行类的名称。我已经尝试在manifest.mf中指定start-class
属性。它仍然将org.springframework.boot.loader.JarLauncher
作为起始类。
您应该能够在ApplicationContext
中执行@Autowire
,然后执行context.getBeansWithAnnotation(SpringBootApplication.class).values().toArray()[0].getClass().getName()
,这将为您提供用@SpringBootApplication
注释的上下文中的第一个(可能也是唯一一个(bean