zoukankan      html  css  js  c++  java
  • Spring_通过注解配置 Bean(1)

    beans-annotation.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 http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd">

    <!-- 指定spring IOC 容器扫描的包 -->
    <!-- 可以通过 resource-pattern 指定扫描的资源 -->
    <!--
    <context:component-scan
    base-package="com.hy.spring.beans.annotation"
    resource-pattern="repository/*.class">
    </context:component-scan>
    -->

    <!-- context:exclude-filter 子节点指定排除哪些指定表达式的组件 -->
    <!-- context:include-filter 子节点指定包含哪些表达式的组件,该节点需要 use-default-filters 配合使用-->
    <context:component-scan
    base-package="com.hy.spring.beans.annotation"
    use-default-filters="false">
    <!--
    <context:exclude-filter type="annotation"
    expression="org.springframework.stereotype.Repository"/>
    -->

    <!-- <context:include-filter type="annotation"
    expression="org.springframework.stereotype.Repository"/>
    -->

    <!-- <context:exclude-filter type="assignable"
    expression="com.hy.spring.beans.annotation.repository.UserRepository"/>
    -->

    <context:include-filter type="assignable"
    expression="com.hy.spring.beans.annotation.repository.UserRepository"/>
    </context:component-scan>


    </beans>

    TestObject.java

    package com.hy.spring.beans.annotation;

    import org.springframework.stereotype.Component;

    @Component
    public class TestObject {

    }

    UserController.java

    package com.hy.spring.beans.annotation.controller;

    import org.springframework.stereotype.Controller;

    @Controller
    public class UserController {
    public void execute(){
    System.out.println("UserController execute....");
    }
    }

    UserRepository.java

    package com.hy.spring.beans.annotation.repository;

    public interface UserRepository {
    public void save();
    }


    UserRepositoryImpl.java

    package com.hy.spring.beans.annotation.repository;

    import org.springframework.stereotype.Repository;

    @Repository("userRepository")
    public class UserRepositoryImpl implements UserRepository{

    public void save() {
    System.out.println("UserRepositoryImpl save....");

    }

    }

    UserService.java

    package com.hy.spring.beans.annotation.service;

    import org.springframework.stereotype.Service;

    @Service
    public class UserService {
    public void add(){
    System.out.println("UserService add...");
    }
    }

  • 相关阅读:
    vuex状态管理demo
    vuex与redux,我们都一样
    vue-quill-editor + element-ui upload实现富文本图片上传
    总结移动端页面开发时需要注意的一些问题
    laravel 运行出错RuntimeException No application encryption key has been specified.
    JS 正则匹配 只匹配汉字
    LINUX统计一个文件中特定字符串出现的次数
    Nginx Log日志统计分析常用命令
    python之mysqldb模块安装
    PHP 可变参数 ( ... ) 和参数解包
  • 原文地址:https://www.cnblogs.com/yang-hao/p/5811691.html
Copyright © 2011-2022 走看看