Spring 4.X - 5.0基本使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/DTJ_74/article/details/53054822

Spring常用注解:

@Component 组件,没有明确的角色。
@Service 在业务逻辑层(service层)使用。
@Repository在数据访问层(dao层)使用。
@Controller在展现层(MVC-SpringMVC或者Struts2中使用)

注入Bean的注解,一般情况下通用。
@Autowired:spring 提供的注解。
@Inject :JSR-330提供的注解。
@Resource:JSR-250提供的注解。
@Configuration :声明当前类是一个配置类,相当于一个配置文件。
@ComponentScan:自动扫描包名下所有使用@Service,@Component @Respository,@Controller的类。并且注册为Bean.


AOP :面向切面编程。
@Aspect 声明一个切面。
@After @Before @Around 切面拦截规则时使用相关。

@Scope时指Spring容器如何创建Bean的实例。

  1. Singleton: 一个Spring容器中只有一个Bean的实例。
  2. Prototype: 每次调用新建一个Bean的实例。
  3. Request :web项目中,给每一个http request新建一个Bean实例。
  4. Session:Web项目中,给每一个http session新建一个Bean实例。
  5. GlobalSession:只在portal应用中有用,给每一个global http session新建一个Bean实例
  6. 另外在Spring Batch中还有一个Scope是使用@StepScope.

Spring EL 表达式:
@Value:
例如:
@Value(“libai”)
private String name;


猜你喜欢

转载自blog.csdn.net/DTJ_74/article/details/53054822