Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Environment.getProperty(String name, Class<T> targetType, T defaultValue); [SPR-8322] #12971

Closed
spring-projects-issues opened this issue May 10, 2011 · 0 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Keith Donald opened SPR-8322 and commented

e.g. would turn this:

@Bean
public JavaMailSender mailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setDefaultEncoding("UTF-8");
    mailSender.setHost(environment.getProperty("mail.host"));
    Integer port = environment.getProperty("mail.port", Integer.class);
    if (port != null) {
        mailSender.setPort(port);
    }
    mailSender.setUsername(environment.getProperty("mail.username"));
    mailSender.setPassword(environment.getProperty("mail.password"));
    Properties properties = new Properties();
    Boolean mailSmtpAuth = environment.getProperty("mail.smtp.auth", Boolean.class);
    if (mailSmtpAuth != null) {
        properties.put("mail.smtp.auth", mailSmtpAuth);
    }
    Boolean mailSmtpStartTls = environment.getProperty("mail.smtp.starttls.enable", Boolean.class);
    if (mailSmtpAuth != null) {
        properties.put("mail.smtp.auth", mailSmtpStartTls);
    }
    mailSender.setJavaMailProperties(properties);
    return mailSender;
}

into this:

@Bean
public JavaMailSender mailSender() {
    JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
    mailSender.setDefaultEncoding("UTF-8");
    mailSender.setHost(environment.getProperty("mail.host"));
    mailSender.setPort(port, environment.getProperty("mail.port", Integer.class, 25));
    mailSender.setUsername(environment.getProperty("mail.username"));
    mailSender.setPassword(environment.getProperty("mail.password"));
    Properties properties = new Properties();
    properties.put("mail.smtp.auth", environment.getProperty("mail.smtp.auth", Boolean.class, false));
    properties.put("mail.smtp.auth", environment.getProperty("mail.smtp.starttls.enable", Boolean.class, false));
    mailSender.setJavaMailProperties(properties);
    return mailSender;
}

Attachments:

Referenced from: commits 3622c6f, dc2d5c1

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.1 M2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant