1. 程式人生 > >spring註解驅動開發基本包掃描配置

spring註解驅動開發基本包掃描配置

更加全面的spring註解配置可以參看spring官方文件,有所有的註解以及對應的配置檔案的配置 

@ComponentScan(value = "com.annotation",useDefaultFilters = false,includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,classes = {Controller.class,ControllerAdvice.class})})
@Configuration
public class MainConfig {

    @Bean(name = "person")
    public Person person(){
        Person person = new Person();
        person.setId(1);
        person.setName("lqf");
        person.setEmail("
[email protected]
"); return person; } }

相關推薦

spring註解驅動開發基本掃描配置

更加全面的spring註解配置可以參看spring官方文件,有所有的註解以及對應的配置檔案的配置  @ComponentScan(value = "com.annotation",useDefaultFilters = false,includeFilters = {@

Spring註解驅動開發——指定配置類和註冊Bean

1、通過註解指定配置類和註冊Bean @Configuration public class MainConfig { @Bean public Person person(){ return new Person("lisi",12);

Spring註解驅動開發】元件註冊-@ComponentScan-自動掃描元件&指定掃描規則

## 寫在前面 > 在實際專案中,我們更多的是使用Spring的包掃描功能對專案中的包進行掃描,凡是在指定的包或子包中的類上標註了@Repository、@Service、@Controller、@Component註解的類都會被掃描到,並將這個類注入到Spring容器中。Spring包掃描功能可以使

Spring註解驅動開發】使用@PropertySource載入配置檔案,我只看這一篇!!

## 寫在前面 > 很多小夥伴都在問:冰河,你的Spring專題更新完了嗎?怎麼感覺像是寫了一半啊?我:沒有更新完呀,整個專題預計會有70多篇。那怎麼更新了一半就去寫別的了呢?那是因為有很多其他的小夥伴在後臺留言說:急需學習一些其他的技術,所以,臨時調整的。放心,Spring專題會持續更新的!這不,今

Spring註解驅動開發

int 接口 wing area web 構造器 async 所有 reg 給容器中註冊組件 1、包掃描+組件標註註解(@Controller/@service/@Repository/@compement) 2、@Bean[導入的第三方包裏面的組件 ] 3、@Sc

Spring註解驅動開發(1):容器

核心容器: Demo: pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:s

Spring註解驅動開發之IOC

getprop student type() tco 簡單 erb als com edt 1、最簡單的註解驅動開發實例: <dependency> <groupId>org.springframework</

0、Spring 註解驅動開發

0、Spring註解驅動開發 0.1 簡介 《Spring註解驅動開發》是一套幫助我們深入瞭解Spring原理機制的教程; 現今SpringBoot、SpringCloud技術非常火熱,作為Spring之上的框架,他們大量使用到了Spring的一些底層註解、原理,比如@Conditional、@

Spring註解驅動開發之AOP2

1、AOP基本搭建: <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <ve

Spring註解驅動開發(二)

AOP-AOP功能測試 /** * 切面類 * @author lfy * * @Aspect: 告訴Spring當前類是一個切面類 * */ @Aspect public class LogAspects { //抽取公共的切入點表示式 //1、本

Spring註解驅動開發——bean的後置處理器

BeanPostProcessor:是一個介面,bean的後置處理器(實際是在bean的初始化前後執行操作) public class MyBeanPostProcessor implements BeanPostProcessor{ /** * bean是容器呼叫

Spring註解驅動開發——FactoryBean介面

使用Spring提供的工廠Bean(FactoryBean)     FactoryBean是一個介面,子類需實現其三個方法:         getObject():獲取物件,必須重寫     

Spring註解驅動開發——匯入元件

1、@Import快速匯入一個元件 容器中註冊元件的方式:     ①包掃描+元件註解(@Controller、@Service、@Repository、@Component)     ②@Bean     ③@Import:值是一個Class[],容器會註冊被匯入的

Spring註解驅動開發——自動裝配(1)

自動裝配:Spring利用依賴注入(DI),完成對IOC容器中各個元件的依賴賦值 1、@Autowired:     預設先按照型別去容器中找相應的元件(applicationContext.get

Spring註解驅動開發——bean的生命週期

Bean的生命週期:bean建立->初始化->銷燬的過程,由容器來管理,容器會在bean進行到當前生命週期時呼叫我們自定義的初始化和銷燬方法 1、通過@Bean的屬性指定初始化和銷燬方法:這兩個方法必須是無入參的 public class Car { pu

Spring註解驅動開發——設定Bean屬性和動態註冊Bean

1、@Scope設定元件作用域 @Configuration public class MainConfigA { @Bean("person") @Scope("singleton") public Person person(){

Spring註解驅動開發(一)

[email protected]註解 這個相當於配置檔案,即告訴spring這個一個配置類。 [email protected] 給容器註冊一個Bean;型別為返回值的型別,id預設是用方法名作為id. @Configurat

一步一步實現Spring4 + Hibernate4 + Freemarker2 的註解驅動開發(二.應用配置

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:mvc="http://www.springframework.or

Spring註解驅動開發】聊聊Spring註解驅動開發那些事兒!

## 寫在前面 > 今天,面了一個工作5年的小夥伴,面試結果不理想啊!也不是我說,工作5年了,問多執行緒的知識:就只知道繼承Thread類和實現Runnable介面!問Java集合,竟然說HashMap是執行緒安全的!問MySQL的MyISAM儲存引擎和InnoDB儲存引擎的區別,竟然說成是MyISA

Spring註解驅動開發】使用@Scope註解設定元件的作用域

## 寫在前面 > Spring容器中的元件預設是單例的,在Spring啟動時就會例項化並初始化這些物件,將其放到Spring容器中,之後,每次獲取物件時,直接從Spring容器中獲取,而不再建立物件。如果每次從Spring容器中獲取物件時,都要建立一個新的例項物件,該如何處理呢?此時就需要使用@Sc