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

  • 相关阅读:
    Longest Common Substring
    未完成 Anagrams
    strStr
    vim的学习笔记
    Compare Strings
    Two Strings Are Anagrams
    KMP算法
    [ 力扣活动0314 ] 300. 最长上升子序列
    [ 力扣活动0317 ] 1160. 拼写单词
    [ 力扣活动0313 ] 169. 多数元素
  • 原文地址:https://www.cnblogs.com/wt7018/p/13338118.html
Copyright © 2011-2022 走看看