zoukankan      html  css  js  c++  java
  • Spring5.X的注解配置项目

    pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>net.cybcclass</groupId>
        <artifactId>cyb_spring</artifactId>
        <version>1.0-SNAPSHOT</version>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>5.2.5.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>5.2.5.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>5.2.5.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
                <version>1.9.5</version>
            </dependency>
        </dependencies>
    </project>

    VideoService.java

    package net.cybclass.sp.servicce;
    
    import net.cybclass.sp.domain.Video;
    
    public interface VideoService {
        int save(Video video);
        Video findById(int id);
    }

    VideoServiceImpl.java

    package net.cybclass.sp.servicce;
    
    import net.cybclass.sp.domain.Video;
    import org.springframework.stereotype.Component;
    
    //@Component("videoService") //相当于配置bean的id
    @Component() //相当于配置bean的id
    public class VideoServiceImpl implements VideoService{
        public int save(Video video) {
            System.out.println("保存Video");
            return 0;
        }
    
        public Video findById(int id) {
            System.out.println("根据id找视频");
            return new Video();
        }
    }

    在实现类上加@Component,若没有取名字的话,默认是,类名首字母小写

    演示

  • 相关阅读:
    使用element-ui table expand展开行实现手风琴效果
    使用js生成二维码和条形码
    js时间戳转换时间、距当前时间
    使用js在浏览器中禁止右键、审查元素、复制功能
    VS Code编辑器插件整理及配置设定
    在vue项目中使用canvas-nest.js,报parameter 1 is not of type 'Element'
    JS中的函数
    Babel 7 初探
    package-lock.json 文件
    Js 中的数组
  • 原文地址:https://www.cnblogs.com/chenyanbin/p/13306857.html
Copyright © 2011-2022 走看看