静态变量与类如果被注解使用
需注意:定义的类一定要有有@Component或者@Service等注解。
静态变量
@Component @PropertySource("classpath:mail.properties") public class TestUtil { private static String star; @Autowired public TestUtil(@Value("${mail.smtp.username}")String star) { TestUtil.star = star; }
@Component public class EmailUtil { private static String emailSender; @Value ("${engine.email.sender}") public void setSender(String sender) { emailSender = sender; } }
静态类
@Component public class StaticFactory { @Autowired public void setDataSource(DataSource dataSource) { StaticFactory.dataSource = dataSource; } private static DataSource dataSource; }