package com.ruoyi;
|
|
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.EnableScheduling;
|
import org.springframework.web.client.RestTemplate;
|
|
import java.net.InetAddress;
|
import java.net.UnknownHostException;
|
|
/**
|
* 启动程序
|
*
|
* @author ruoyi
|
*/
|
@Slf4j
|
@EnableScheduling//开启定时任务
|
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
|
public class RuoYiAppletApplication
|
{
|
public static void main(String[] args) throws UnknownHostException {
|
ConfigurableApplicationContext application = SpringApplication.run(RuoYiAppletApplication.class, args);
|
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"));
|
}
|
|
/**
|
* 当不存在此 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;
|
}
|
|
}
|