1. 程式人生 > >Spring中的@Bean註解在方法上的作用

Spring中的@Bean註解在方法上的作用

首先我們看一下這個註解的類

import org.springframework.context.annotation.Bean;

 

@Bean("dd")
    public User getControllBean(){
        User user=new User();
        user.setPassword("123456");
        user.setUsername("nihao");
        return user;
    }

其實就是建立一個上下文的bean物件,,跟配置檔案中

 

配置spring容器(應用上下文)

的 <bean id="bb"  class="xxx.xx.x"></bean>一樣