zoukankan      html  css  js  c++  java
  • spring 注解开发

    一、环境

    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

  • 相关阅读:
    搭建Jumpserver
    支付功能流程图
    我是如何招聘程序员的
    从问题域看hadoop的各种技术
    转一篇做BI项目的好文
    关于数据倾斜的问题
    技能的十一个级别
    企业计划体系的变迁:从ERP到APS再到SCP
    别浪费自己的高学历
    一个CTO谈自己的技术架构体系
  • 原文地址:https://www.cnblogs.com/wt7018/p/13338118.html
Copyright © 2011-2022 走看看