聲明Bean的註解
@Component組件:沒有明確的角色
@Service :業務層
@Repository: 數據層
@Controller :控制層
注入Bean的註解
@Autowired: spring 提供
@Inject:JSR-330提供
@Resource:JSR-250
配置類:
@Configuration 聲明配置類 相當於XML文件
@ComponentScan 掃描包下聲明的Bean
讀取配置類文件 AnnotationConfigApplicationContext 類
Aop:
@ASpect 聲明爲一個切面
@pointCut 聲明切點 用execution(*空格***)攔截
@After @Before
配置類
@EnableAspectjAutoProxy 開啓spring對Aspectj的支持
@Scope 描述如何新建Bean
@Scope(“Single”)//整個容器只有一個Bean
Prototype: 每次調用新建
Request : 每個request 新建
Session:
GlobalSession: 只在Protal應用
@Value 賦值
@PropertySource(“”) 引入文本文件
@Value(“123”) @Value(“#{demoService.another}”)//系統信息 @Value(“${book.name}”)//配置文件信息
Bean 的銷燬
@PostConstruct 構造函數之後執行
@PreDestory Bean銷燬之前執行
@profile : 支持不同環境下不同配置
使用 context.getEnvironment().setActiveProfiles("") context.register(class) context.refresh();
@EnableAsync 開啓異步支持
@Async 聲明爲一個異步任務
@EnableScheduling 開啓計劃任務支持
@Scheduled 計劃任務
fixedRate=5000 每隔5s執行
fixedDelay 延遲
cron 指定時間
@Conditional 滿足條件創建bean 實現condition接口 matches方法
@Conditional( 實現condition接口 的類)
@EnableWebMvc 開啓對mvc支持
@EnableCaching 開啓註解式緩存支持