| | |
| | | package com.finance; |
| | | |
| | | import com.finance.system.service.AsyncService; |
| | | import java.net.InetAddress; |
| | | import java.net.UnknownHostException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.ApplicationRunner; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
| | |
| | | * @author ruoyi |
| | | */ |
| | | @Slf4j |
| | | @EnableScheduling//开启定时任务 |
| | | @EnableScheduling// 开启定时任务 |
| | | @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) |
| | | public class FinanceAdminDeptApplication { |
| | | |
| | | @Autowired |
| | | private AsyncService asyncService; |
| | | |
| | | public static void main(String[] args) throws UnknownHostException { |
| | | ConfigurableApplicationContext application = SpringApplication.run( |
| | |
| | | log.info("\n----------------------------------------------------------\n\t" + |
| | | "应用 '{}' 运行成功! 访问连接:\n\t" + |
| | | "Swagger文档: \t\thttp://{}:{}/doc.html\n" + |
| | | "----------------------------------------------------------" , |
| | | env.getProperty("spring.application.name" , "后台"), |
| | | "----------------------------------------------------------", |
| | | env.getProperty("spring.application.name", "后台"), |
| | | InetAddress.getLocalHost().getHostAddress(), |
| | | env.getProperty("server.port" , "8081")); |
| | | env.getProperty("server.port", "8081")); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Bean |
| | | @ConditionalOnMissingBean(name = "restTemplate") |
| | | public RestTemplate wxRestTemplate() { |
| | | //复杂构造函数的使用 |
| | | // 复杂构造函数的使用 |
| | | SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); |
| | | // 设置超时 |
| | | requestFactory.setConnectTimeout(6000); |
| | |
| | | return restTemplate; |
| | | } |
| | | |
| | | @Bean |
| | | public ApplicationRunner applicationRunner() { |
| | | return applicationArguments -> { |
| | | long startTime = System.currentTimeMillis(); |
| | | System.out.println(Thread.currentThread().getName() + ":开始调用异步业务"); |
| | | asyncService.asyncTask(); |
| | | long endTime = System.currentTimeMillis(); |
| | | System.out.println( |
| | | Thread.currentThread().getName() + ":调用异步业务结束,耗时:" + (endTime |
| | | - startTime)); |
| | | }; |
| | | } |
| | | |
| | | } |