mitao
2024-04-19 b21c37b7899b17dede7773db3c799aab1063ae1c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.finance;
 
import java.net.InetAddress;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.client.RestTemplate;
 
/**
 * 启动程序
 *
 * @author ruoyi
 */
@Slf4j
@EnableAsync
@EnableScheduling//开启定时任务
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class FinanceManageApplication {
 
    public static void main(String[] args) {
 
        ConfigurableApplicationContext application = SpringApplication.run(
                FinanceManageApplication.class, args);
        try {
 
            Environment env = application.getEnvironment();
            log.info("\n----------------------------------------------------------\n\t" +
                            "应用 '{}' 运行成功! 访问连接:\n\t" +
                            "Swagger文档: \t\thttp://{}:{}/doc.html\n" +
                            "----------------------------------------------------------" ,
                    env.getProperty("spring.application.name" , "后台"),
                    InetAddress.getLocalHost().getHostAddress(),
                    env.getProperty("server.port" , "8081"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
 
    /**
     * 当不存在此 wxRestTemplate 使用此方法的bean注入
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean(name = "restTemplate")
    public RestTemplate wxRestTemplate() {
        //复杂构造函数的使用
        SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
        // 设置超时
        requestFactory.setConnectTimeout(6000);
        requestFactory.setReadTimeout(6000);
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.setRequestFactory(requestFactory);
        return restTemplate;
    }
 
}