SpringBoot 启动普通java工程
2020-03-28 01:55:16 2515
- 引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<version>2.0.9</version>
</dependency>
- 需要某个类实现
CommandLineRunner
接口,在run
方法内写具体代码
package com.xx.main;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class StartMain implements CommandLineRunner {
@Autowired
private IPService ipService;
/**
* 实际的入口函数
*
* @param args
* @throws Exception
*/
public void run(String... args) throws Exception {
//code
System.out.println("启动成功");
}
}
- Springboot启动类照旧
package com.xx;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
运行,控制台输出
启动成功