mail.username=xue@163.com
mail.password=xue
mail.host=smtp.163.com
mail.smtp.auth=true
import org.springframework.beans.factory.annotation.Value;
public class MailConfig {@Value("${mail.username}")
private String username;
@Value("${mail.password}")
private String password;
@Value("${mail.host}")
private String host;
}
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class MailConfig {
public static String username;
public static String password;
public static String host;
@Value("${mail.username}")
public void setUsername(String username) {this.username = username;}
@Value("${mail.password}")
public void setPassword(String password) {this.password = password;}
@Value("${mail.host}")
public void setHost(String host) {this.host = host;}
}
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@Component
public class MailConfig {
public static String USERNAME;
public static String PASSWORD;
public static String HOST;
@Value("${mail.username}")
private String username;
@Value("${mail.password}")
private String password;
@Value("${mail.host}")
private String host;
@PostConstruct
public void init() {
USERNAME = username;
PASSWORD = password;
HOST = host;
}
}