“Spring Boot Console Application”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) (建立内容为“1”的新页面) |
Jihongchang(讨论 | 贡献) (→模板) |
||
(未显示同一用户的2个中间版本) | |||
第1行: | 第1行: | ||
− | + | === pom.xml === | |
+ | |||
+ | ==== 继承 ==== | ||
+ | <syntaxhighlight lang="xml"> | ||
+ | <parent> | ||
+ | <groupId>org.springframework.boot</groupId> | ||
+ | <artifactId>spring-boot-starter-parent</artifactId> | ||
+ | <version>2.4.0</version> | ||
+ | </parent> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==== 依赖 ==== | ||
+ | <syntaxhighlight lang="xml"> | ||
+ | <dependency> | ||
+ | <groupId>org.springframework.boot</groupId> | ||
+ | <artifactId>spring-boot-starter</artifactId> | ||
+ | </dependency> | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | ==== 启动类 ==== | ||
+ | <syntaxhighlight lang="java"> | ||
+ | @SpringBootApplication | ||
+ | public class SpringBootConsoleApplication | ||
+ | implements CommandLineRunner { | ||
+ | |||
+ | private static Logger LOG = LoggerFactory | ||
+ | .getLogger(SpringBootConsoleApplication.class); | ||
+ | |||
+ | public static void main(String[] args) { | ||
+ | LOG.info("STARTING THE APPLICATION"); | ||
+ | SpringApplication.run(SpringBootConsoleApplication.class, args); | ||
+ | LOG.info("APPLICATION FINISHED"); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public void run(String... args) { | ||
+ | LOG.info("EXECUTING : command line runner"); | ||
+ | |||
+ | for (int i = 0; i < args.length; ++i) { | ||
+ | LOG.info("args[{}]: {}", i, args[i]); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | === 模板 === | ||
+ | https://github.com/jihch/spring-boot-console-app |
2022年12月8日 (四) 03:37的最新版本
pom.xml
继承
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
</parent>
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
启动类
@SpringBootApplication
public class SpringBootConsoleApplication
implements CommandLineRunner {
private static Logger LOG = LoggerFactory
.getLogger(SpringBootConsoleApplication.class);
public static void main(String[] args) {
LOG.info("STARTING THE APPLICATION");
SpringApplication.run(SpringBootConsoleApplication.class, args);
LOG.info("APPLICATION FINISHED");
}
@Override
public void run(String... args) {
LOG.info("EXECUTING : command line runner");
for (int i = 0; i < args.length; ++i) {
LOG.info("args[{}]: {}", i, args[i]);
}
}
}