pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.asiainfo.cc</groupId>
<artifactId>mail-send</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- 指定一下jdk的版本 ,这里我们使用jdk 1.7 ,默认是1.6 -->
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
Application.yml
# Server settings
test:
msg: 0/10 * * * * ?
loginname: cc@sina.com
password: 123
server:
profiles: server1
port: 8080
address: 127.0.0.1
---
server:
profiles: server2
port: 8081
address: 127.0.0.2
# SPRING PROFILES
spring:
# HTTP ENCODING
http:
encoding.charset: UTF-8
encoding.enable: true
encoding.force: true
Application.java
@SpringBootApplication
@EnableScheduling
//@ImportResource(locations={"classpath:dubbo-client.xml"})
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).properties(
"spring.config.active=classpath:server1",
"spring.config.active=classpath:server2").run(args);
}
}
Task
@Component
public class MailSending {
@Value("${test.loginname}")
private String loginname;
@Value("${test.password}")
private String password;
// @Autowired
// private IDubboAppUserManagementSV iDubboAppUserManagementSV;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Scheduled(cron="${test.msg}") //每十秒执行一次
// @Scheduled(cron="0 0/1 * * * ?") //每十秒执行一次
public void statusCheck() {
logger.info("每分钟执行一次。开始……");
new MailSending().send();
logger.info("每分钟执行一次。结束。");
}
void send(){
System.out.println("发送成功");
}
}