@EnableTransactionManagement(proxyTargetClass = true) // 註解事務管理,等同於xml配置的 <tx:annotation-driven />java
@EnableAsync //異步調用spring
@EnableAspectJAutoProxy // 支持@Aspect數據庫
@EnableConfigurationProperties // 支持 @ConfigurationProperties(prefix = "tddl")mybatis
@Configuration修飾配置類,使用 @Value 指定匹配, 啓動類須要增長 @EnableAutoConfiguration 或者 @SpringBootApplicationapp
@ConfigurationProperties 修飾配置類,「prefix + 變量名」 指定匹配 ,配置類的成員變量能夠是對象。啓動類須要增長: @EnableConfigurationProperties指定prefix異步
import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.ImportAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ImportResource; @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class }) @EnableDiscoveryClient @EnableFeignClients @EnableConfigurationProperties @ImportResource("classpath:dependence.xml") @MapperScan(basePackages = { "com.noob.retry.dao", "com.noob.mics.dao" }) @ComponentScan(value = { "com.noob.mics", "com.noob.common" }) @ImportAutoConfiguration(exclude = { }) public class NoobApplication { public static void main(String[] args) { System.setProperty("PROJECT_ID", "dev"); SpringApplication.run(NoobApplication .class, args); } }
import lombok.Data; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; /** */ @Configuration @Data public class ApplicationConfig { /** * 應用名 */ @Value("${application.name}") private String appName; /** * 日報發件人. */ @Value("${reportFromMail}") private String reportFromMail; }
import javax.annotation.PostConstruct; import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; /** * 屬性文件對應配置的key 與 prefix + 變量名 匹配。 對象內部成員變量能夠是對象。 * */ @ConfigurationProperties(prefix="noob.tddl") @Component @Data public class Config { private String dbNamePrefix; //數據庫名稱前綴 private int dbCount; //數據庫的個數 private int tableCountForEachDb; //每一個庫中表的個數 private int tableCount; //表總數 @PostConstruct public void log() { System.out.println("DbConfig [dbNamePrefix=" + getDbNamePrefix() + ", dbCount=" + getDbCount() + ", tableCountForEachDb=" + getTableCountForEachDb() + ", tableCount=" + getTableCount() + "]"); } }