首页 > 编程语言 > 详细

spring 注解开发

时间:2020-07-19 11:36:35      阅读:53      评论:0      收藏:0      [点我收藏+]

一、环境

1、导入包 maven

2、xml配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        https://www.springframework.org/schema/context/spring-context.xsd">
<!--    扫描-->
    <context:component-scan base-package="com.wt.pojo"/>
    <context:annotation-config/>

</beans>

二、具体实现

1、bean

@Component
public class User {
}

2、属性注入

package com.wt.pojo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class User {
    @Value("wt")
    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

 

3、衍生注解

dao [@Repository]

service [@Service]

controller[@Controller]

将类注入到spring容器中

4、自动装配注解

5、作用域注解

@Scope

spring 注解开发

原文:https://www.cnblogs.com/wt7018/p/13338118.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!