pom文件配置
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.example.weather.App</mainClass>
</configuration>
</plugin>
控制器配置
package com.example.weather;
import com.example.weather.mode.controller.WeatherEnviromentController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
/**
* @Auther:
* @Date: 2021/07/28/9:17
* @Description:
*/
@SpringBootApplication
public class App implements ApplicationRunner {
public static void main(String[] args) {
ConfigurableApplicationContext context = SpringApplication.run(App.class, args);
WeatherEnviromentController weatherEnviromentController = context.getBean(WeatherEnviromentController.class);
weatherEnviromentController.selectWeather();
context.close();//关闭容器
}
@Override
public void run(ApplicationArguments args) throws Exception {
System.out.println("开始执行任务");
}
}