JavaEE学习日志(八十九): spring注解开发详解

查看文件内容时,排除注释行查看的方法 【grep -v  "^#" /etc/inittab | more】查看/etc/inittab文件,并过滤注释行 阅读详情

JavaEE学习日志持续更新----> 必看!JavaEE学习路线(文章总汇)

Spring注解开发

注解开发入门

1、引入依赖
2、配置文件

  • 头文件增加命名空间和约束
  • 开启注解
 <context:component-scan base-package="包名"></context:component-scan>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       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.xsd
">
    <!--
        开启注解,指定扫描的包:context:component-scan
        引入context名称空间,引入约束

        base-package:指定要扫描的包,扫描的是包和其子包
    -->
    <context:component-scan base-package="com.itheima"></context:component-scan>
</beans>

3、在需要创建的类上添加注解@Component

package com.itheima.dao.impl;

import com.itheima.dao.UserDao;
import org.springframework.stereotype.Component;

@Component
public class UserDaoImpl implements UserDao {
}

4、测试

@Test
    public void test(){
        //创建容器对象
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        //获取对象
        UserDao userDao = ac.getBean(UserDao.class);
        System.out.println(userDao);
    }

Component注解

@Component标志在类上,不能用在方法上
作用:只要扫描了包,就会创建对象

1、衍生了三个子注解

  • @Controller一般用于web层
  • @Service一般用于业务层
  • @Repository一般用于持久层

作用:三个的作用和@Component都是一样的,但最好别混用。

2、@Component中有个属性value=""
可以用于指定名字,默认的名称是简单类名首字母小写
(UserServiceImpl->userServiceImpl)

@Component("userService")

相当于xml中

<bean id="userService" class="全限类名"></bean>

自动注入@Autowired

如果想在UserService中调用UserDao,则只需要加上@Autowired注解即可。

可以标记在属性或set方法上,如果标记在属性上,可以没有set方法

@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDao;

    public void print(){
        userDao.print();
    }
}

特点:自动按照类型注入
流程:当属性或方法(set方法)标记了@Autowired,那么会自动在容器中查找该属性类型的对象,如果有且只有一个,则注入。

注意:如果有两个userDao的实现类,则会报错。
解决方法:
一、在@Autowired下配置上需要注入的名称,使用注解@Qualifier

@Qualifier("userDaoImpl2")
@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    @Qualifier("userDaoImpl2")
    UserDao userDao;

    public void print(){
        userDao.print();
    }
}

二、根据属性名注入

@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    UserDao userDaoImpl2;

    public void print(){
        userDaoImpl2.print();
    }
}

自动注入@Resource

如果没有@Resource注解,则写入依赖

<dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>1.3.1</version>
        </dependency>

流程:当属性或方法(set方法)标记了@Resource

  • 按照名称查找:会自动按照名称注入,如果指定了名称,则按照名称注入;如果没有指定名字,则按照属性名注入。
  • 按照类型查找:如果名称没有找到,则按照类型注入;类型有多个则抛出异常

按照指定的名称注入

@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource(name="userDaoImpl2")
    UserDao userDao;

    public void print(){
        userDao.print();
    }
}

按照属性名注入

@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    UserDao userDaoImpl2;

    public void print(){
        userDaoImpl2.print();
    }
}

按照类型注入(属性名找不到对应的类时):如果有多个则报异常

@Service("userService")
public class UserServiceImpl implements UserService {
    @Resource
    UserDao userDao;

    public void print(){
        userDao.print();
    }
}

@Autowired和@Resource区别
@Autowired:

  • 默认按照类型注入,如果类型有多个,则按照名称注入
  • spring提供

@Resource:

  • 默认按照名称注入,如果名称没有找到,则按照类型注入
  • jdk提供

使用半注解半xml改造账户CRUD

开启注解中有两个属性
1、context:include-filter:指定包含过滤

  • type="annotation"按照类型过滤
  • expression=""过滤的表达式

在下边代码中的含义:只扫描标记了Controller注解的类

2、context:exclude-filter:指定排除过滤

  • type="annotation"按照类型过滤
  • expression=""过滤的表达式

在下边代码中的含义:除了Controller注解都会扫描

<!--开启注解,扫描包-->
    <context:component-scan base-package="com.itheima">
        <!--
            context:include-filter:指定包含过滤
                type="annotation"按照类型过滤
                expression=""过滤的表达式

                只扫描标记了Controller注解的类
        -->
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <!--
            context:exclude-filter:指定排除过滤
                type="annotation"按照类型过滤
                expression=""过滤的表达式

                除了Controller注解都会扫描
        -->
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

配置文件

<?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.xsd">

    <!--开启注解,扫描包-->
    <context:component-scan base-package="com.itheima"></context:component-scan>

    <!--创建qr对象,需要数据源对象,通过构造方法的参数类型注入-->
    <bean id="qr" class="org.apache.commons.dbutils.QueryRunner">
        <constructor-arg type="javax.sql.DataSource" ref="dataSource"></constructor-arg>
    </bean>
    <!--创建数据源对象:需要注入四个参数,通过set方法注入-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/spring"></property>
        <property name="user" value="root"></property>
        <property name="password" value="root"></property>
    </bean>
</beans>

AccountDaoImpl

@Repository("accountDao")
public class AccountDaoImpl implements AccountDao {
    @Autowired
    QueryRunner qr;
    //...省略
}

AccountServiceImpl

import com.itheima.dao.AccountDao;
import com.itheima.dao.impl.AccountDaoImpl;
import com.itheima.domain.Account;
import com.itheima.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("accountService")
public class AccountServiceImpl implements AccountService {
    //创建容器,使用依赖注入
    @Autowired
    private AccountDao accountDao;
    //...省略
}

测试类

@Test
    public void test(){
        //创建容器
        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        //创建service对象
        AccountService accountService = ac.getBean("accountService",AccountService.class);
        List<Account> accountList = accountService.findAll();
        for (Account account : accountList) {
            System.out.println(account);
        }
    }

纯注解开发案例

使用纯注解改造账户CRUD

一、创建SpringConfiguration.java

  1. 标记该类为配置文件类 @Configuration
  2. 指定注解扫描的包路径 @ComponentScan({"com.itheima"})
  3. 引入其他配置文件类 @Import({JDBCConfiguration.class})
package com.itheima.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * 1、标记该类为配置文件类    @Configuration
 * 2、指定注解扫描的包路径    @ComponentScan({"com.itheima"})
 * 3、引入其他配置文件类      @Import({JDBCConfiguration.class})
 *
 *
 */
@Configuration
@ComponentScan({"com.itheima"})
@Import({JDBCConfiguration.class})
public class SpringConfiguration {
}

二、创建JDBCConfiguration.java

  • @Configuration:可以省略
  • @Bean("name"):用在方法上,用来指定方法创建的对象存到容器中,一般用于别人的类,相当于<bean>标签
    "name"就是在容器中的名称
package com.itheima.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;

/**
 * 配置持久层的对象
 * @Configuration:可以省略
 * @Bean("name"):用在方法上,用来指定方法创建的对象存到容器中
 *          "name"就是在容器中的名称
 *
 */
@Configuration
public class JDBCConfiguration {
    @Bean("queryRunner")
    public QueryRunner createQueryRunner(DataSource dataSource){
        //需要通过构造方法,注入dataSource
        QueryRunner queryRunner = new QueryRunner(dataSource);
        return queryRunner;
    }
    /**
     * 创建数据源对象:dataSource
     * @return
     */
    @Bean("dataSource")
    public DataSource createDataSource(){
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setJdbcUrl("jdbc:mysql://localhost:3306/spring");
        dataSource.setUser("root");
        dataSource.setPassword("root");
        try {
            dataSource.setDriverClass("com.mysql.jdbc.Driver");
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }
        return dataSource;
    }
}

三、测试
注意:使用ApplicationContext ac = new AnnotationConfigApplicationContext(SpringConfiguration.class);

 @Test
    public void test(){
        //创建容器
//        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        //纯注解创建容器对象
        ApplicationContext ac = new AnnotationConfigApplicationContext(SpringConfiguration.class);

        //创建service对象
        AccountService accountService = ac.getBean("accountService",AccountService.class);
        List<Account> accountList = accountService.findAll();
        for (Account account : accountList) {
            System.out.println(account);
        }
    }

改造纯注解

改造一:数据库的一些属性写死了,把他们放到配置文件中

  • @PropertySource({"jdbc.properties"})引入properties文件
  • @Value给属性赋值
jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring
jdbc.username=root
jdbc.password=root
package com.itheima.config;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;
import java.beans.PropertyVetoException;

/**
 * 配置持久层的对象
 * @Configuration:可以省略
 * @Bean("name"):用在方法上,用来指定方法创建的对象存到容器中
 *          "name"就是在容器中的名称
 *
 */
@Configuration
@PropertySource({"jdbc.properties"})
public class JDBCConfiguration {
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.driver}")
    private String driverClass;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;

    @Bean("queryRunner")
    public QueryRunner createQueryRunner(DataSource dataSource){
        //需要通过构造方法,注入dataSource
        QueryRunner queryRunner = new QueryRunner(dataSource);
        return queryRunner;
    }
    /**
     * 创建数据源对象:dataSource
     * @return
     */
    @Bean("dataSource")
    public DataSource createDataSource(){
        ComboPooledDataSource dataSource = new ComboPooledDataSource();
        dataSource.setJdbcUrl(url);
        dataSource.setUser(username);
        dataSource.setPassword(password);
        try {
            dataSource.setDriverClass(driverClass);
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }
        return dataSource;
    }
}

改造二:创建的对象默认是单例模式,将他改成多例模式

在类上添加注解@Scope("prototype")

@Repository("accountDao")
@Scope("prototype")
public class AccountDaoImpl implements AccountDao 

改造三:可以添加对象的初始化和销毁方法(一般不用)

  • @PostConstruct:相当于bean标签的属性init-method,指定初始化方法
  • @PreDestroy:相当于bean标签的属性:destroy-method,指定对象的销毁方法

xml引入外部文件

一、xml中引入xml

关键代码

<import resource="classpath:applicationContext-dao.xml"></import>

applicationContext.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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <!--引入外部属性文件-->
    <import resource="classpath:applicationContext-dao.xml"></import>
    <!--创建AccountService对象:需要AccountDao对象,依赖注入dao对象-->
    <bean id="accountService" class="com.itheima.service.impl.AccountServiceImpl">
        <property name="accountDao" ref="accountDao"></property>
    </bean>

</beans>

applicationContext-dao.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"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    <!--创建AccountDao对象,需要qr-->
    <bean id="accountDao" class="com.itheima.dao.impl.AccountDaoImpl">
        <!--通过set方法注入qr-->
        <property name="qr" ref="qr"></property>
    </bean>
    <!--创建qr对象,需要数据源对象,通过构造方法的参数类型注入-->
    <bean id="qr" class="org.apache.commons.dbutils.QueryRunner">
        <constructor-arg type="javax.sql.DataSource" ref="dataSource"></constructor-arg>
    </bean>
    <!--创建数据源对象:需要注入四个参数,通过set方法注入-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"></property>
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/spring"></property>
        <property name="user" value="root"></property>
        <property name="password" value="root"></property>
    </bean>
</beans>

二、xml中引入properties文件

关键代码

<context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>

applicationContext-dap.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.xsd">
    <!--创建AccountDao对象,需要qr-->
    <bean id="accountDao" class="com.itheima.dao.impl.AccountDaoImpl">
        <!--通过set方法注入qr-->
        <property name="qr" ref="qr"></property>
    </bean>
    <!--创建qr对象,需要数据源对象,通过构造方法的参数类型注入-->
    <bean id="qr" class="org.apache.commons.dbutils.QueryRunner">
        <constructor-arg type="javax.sql.DataSource" ref="dataSource"></constructor-arg>
    </bean>
    <!--创建数据源对象:需要注入四个参数,通过set方法注入-->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${jdbc.driver}"></property>
        <property name="jdbcUrl" value="${jdbc.url}"></property>
        <property name="user" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
    </bean>

    <!--引入外部属性文件-->
    <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
</beans>

jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring
jdbc.username=root
jdbc.password=root
JavaEE轻量级框架6个实验报告 JavaEE轻量级框架 史胜辉 王春明 卢培军编著 6个实验报告 期末作业必备) 立即下载

相关推荐

Win10下Altera USB-Blaster驱动安装详解:禁用数字签名与排查指南

在嵌入式开发和FPGA调试过程中,驱动安装是工程师绕不开的环节,尤其是当操作系统对驱动签名有严格限制时,硬件往往无法被正常识别。数字签名是系统验证驱动程序来源和完整性的重要机制,Win10出于安全考虑,默认拒绝加载未经签名的驱动,这正是Altera USB-Blaster下载器在设备管理器中显示未知设备或黄色感叹号的根本原因。通过理解设备管理器的排查逻辑,掌握临时禁用驱动强制签名或开启测试模式的方法,配合正确的驱动文件路径选择与手动安装操作,即可解决Quartus无法检测到下载器的问题。这一流程同样适用于许

weixin_29164497的博客 254

Spring注解context:component-scan base-package使用

小王:想要把一个bean交给Spring去管理,你想怎么做! 小李:简单啊,在Spring的配置文件里面配置<bean id="" class=""></bean>不就行了。 小王:不行啊,我们的项目太恶心了,用了一万个bean,写配置文件快累死了,密密麻麻的看不清楚 小李:额!这个也太奇葩了,怎么办,翻翻书吧,有没有好方法。 这是什么?自动装配?我擦,这么神奇?下面我们...

MyGGBond的博客 9643

四、通过Socket实现跟AGV小车通信(仅做Demo演示,跟实际工厂运行无关)

在通常情况下AGV的开发是使用PLC或者单片机,我们会使用MOXA等串口服务器配置485或者232通信。 我们会将AGV的MOXA设备配置成服务端。我们按照一定的数据协议从PLC或者单片机获得AGV的信息。 今天我抛开这些协议,通过工具模拟实现openTCS的Socket通信。 我这边用winform写了一个简单的Socket服务端工具(超简单那种) 我们的代码是基于第一篇文章的,具体参照 ht...

苏州周某人 1万+

Spring注解开发

就相当于由于使用了Java配置类替代配置文件,所以读取spring核心配置文件初始化容器对象切换为读取Java配置类初始化容器对象。同时,在核心配置文件中通过扫描组件加载bean(在类中使用@Component注解,而在容器中需要找到这个bean)1所述方法虽然用到了@component注解简化了配置,但在配置文件中仍需要写出扫描的范围。@Service :用于业务层bean定义。

ruoxiuqaq的博客 135

从实验室到晶圆厂:一文看懂二维半导体(如MoS2)的CVD生长与晶体管制造挑战

本文深入探讨了二维半导体(如MoS2)从实验室研究到晶圆厂量产的CVD生长与晶体管制造关键技术挑战。重点分析了晶圆级二维半导体的CVD生长工艺优化、晶体管制造的四大界面工程难题,以及掺杂与集成的产业化解决方案,为二维半导体在集成电路领域的应用提供技术参考。

weixin_42651748的博客 476

Claude Code插件安装与VSCode深度集成实战指南

Claude Code是一款专为IDE设计的AI编程助手插件,其核心价值在于将自然语言意图转化为可运行代码,从而优化开发者认知带宽分配。它依赖Node.js运行时、git版本上下文和VSCode编辑器API三者协同工作,技术原理涉及本地进程通信、权限策略绕过、上下文感知补全等关键机制。该工具显著提升工程效率,适用于CLI开发、EXIF元数据处理、异步逻辑生成等典型JavaScript/TypeScript应用场景。本文聚焦Claude Code插件在VSCode中的真实落地链路,覆盖Windows/macO

weixin_34006468的博客 487

第5篇 基于注解的 IOC 配置

第5篇 基于注解的 IOC 配置 1 明确:写在最前 学习基于注解的 IoC 配置,大家脑海里首先得有一个认知,即注解配置和 xml 配置要实现的功能都是一样 的,都是要降低程序间的耦合。只是配置的形式不一样。 关于实际的开发中到底使用xml还是注解,每家公司有着不同的使用习惯。所以这两种配置方式我们都需要掌 握。 我们在讲解注解配置时,采用上一章节的案例,把 spring 的 xml ...

生锈的齿轮 288

真格量化——GFTD策略

#!/usr/bin/env python # coding:utf-8 from PoboAPI import * import datetime import numpy as np import math #开始时间,用于初始化一些参数 def OnStart(context) : print "I\'m starting..." #设置全局变量 g.signalcount = 0 g.signal_list = [] g.buysignal = 0 .

qq_26742269的博客 1288

spring_day02_基于注解的spring配置

一、前提 注解配置和xml配置要实现的功能都是一样的,都是要降低程序间的耦合,只是配置的形式不一样 实际的开发中到底使用xml还是注解,每家公司有着不同的使用习惯 二、入门 1、环境搭建 1.1 导入jar包 在基于注解的配置中,我们还要多拷贝一个aop的jar包 1.2 添加约束 xmlns:context="http://www.springframework.org/s...

Jesson_study 333

OpenClaw 报错 TypeError: Cannot read properties of undefined (reading ‘prototype‘):Node.js 版本不兼容

国产化环境中部署OpenClaw云边协同平台时,出现"TypeError: Cannot read properties of undefined (reading 'prototype')"报错。经分析发现根本原因是Node.js版本与依赖生态不兼容,新版本Node(如v21)移除了旧依赖使用的内部API。解决方案包括:1)使用nvm切换至兼容的Node 16/18 LTS版本;2)容器化部署固定Node版本;3)遵循官方推荐的引擎版本范围。该问题揭示现代工程中版本管理的重要性,

博客 2319

127. 答网友疑问:ABAP Function Module 如何支持内表结构不确定的动态输入参数

ABAP RTTI 的全称是 Runtime Type Identification. 使用 RTTI,ABAP 开发人员可以在运行时获取关于数据对象的各种信息,包括其数据类型、字段列表(如果数据是Structure 或者内表的话)以及这些字段的技术属性,比如字段名称,字段数据类型,长度等等。对于这些字段信息,ABAP 提供了一组特殊的类和接口,包括 CL_ABAP_TYPEDESCR、CL_ABAP_STRUCTDESCR、CL_ABAP_TABLEDESCR 等等。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1774

SpringMVC 组件解析

无

LY3054404567的博客 310

Python爬虫实战:逆向分析+异步技术高效抓取微信公众号文章

逆向突破:解析公众号核心接口参数,破解登录态与加密规则;高性能:异步协程+连接池,单进程日均抓取1000+篇文章;高稳定性:自动刷新登录态、IP代理轮换,无人工干预持续运行;高完整性:覆盖文章全量字段,清洗后可直接用于数据分析。接入消息队列(Kafka),实现分布式多公众号并行爬取;增加文章配图下载模块,完整存档多媒体内容;接入Elasticsearch,实现文章全文检索与关键词分析。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 3269

Spring扫描组件<context:component-scan base-package=" "/>的使用详解

1.如果不想在xml文件中配置bean,我们可以给我们的类加上spring组件注解,只需再配置下spring的扫描器就可以实现bean的自动载入。 需要注意的是: 在base-package指明一个包: 表明com.b505包及其子包中,如果某个类的头上带有特定的注解 @Component,@Repository,@Service,@Controller,就会将

冰冻非一日之寒 4万+

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

SSM框架--Spring入门二

今日内容 容器相关 容器继承体系 获取Bean的方式 注解+XML实现IoC 全注解实现IoC Spring整合其他框架 Mybatis JUnit 1. 容器 1.1 基础代码环境 基础代代码环境 依赖 <!-- 略 --> BookDao package com.itheima.dao; public interface BookDao { public void save(); } BooDaoImpl package co

weixin_41438423的博客 388

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

spring配置<context:component-scan base-package=””/>

base-package属性,指定扫描的包,配置扫描多个包,可以通过“,”逗号隔开; use-default-filters属性是使用默认过滤器,默认值为true, 首先通过exclude-filter 进行黑名单过滤; 然后通过include-filter 进行白名单过滤; 否则默认选中扫描。(true则会对除了黑名单外进行扫描管理,false则不使用默认过滤器) context:inclu

menghuanzhiming的博客 6045

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

<context:component-scan base-package=com.xxx.xxx/ >包扫描注解

转自:http://blog.csdn.net/sxbjffsg163/article/details/9955517 扫描指定的包中的类上的注解,常用的注解有: @Controller 声明Action组件 @Service    声明Service组件    @Service("myMovieLister")  @Repository 声明Dao组件 @Componen

Manketon的专栏 2467

spring(2)

基于注解的IOC 配置 <context:component-scan base-package="com.itheima"></context:component-scan> 用于创建对象的 相当于:<bean id="" class=""> @Component @Controller @Service @Repository 用于注入数据的 相当于:&...

weixin_42968500的博客 159

Spring使用注解开发(四)

该类被注解标记,则是一个配置类,作用和bean一样,相当于用java代码代替XML文件配置 @Configuration 指定当前类是一个配置类 当AnnotationConfigApplicationContext对象参数中声明了该类,此注解可以省略,但是如果该类没有配置该注解时,通过@ComponentScan扫描其他包时,如果扫描其他的类中没有配置@Configuration注解则不能生效 @ComponentScan 作用:用于通过注解指定spring在创建容器时要扫描的包 属性:value 和ba

weixin_45608165的博客 178

spring(二)——spring-jdbc、spring中(QueryRunner、整合归纳连接池、常用注解、单元测试、纯注解实现业务逻辑)

QueryRunner与Spring-jdbc总结 QueryRunner自动映射,所以bean实体类属性名必须与数据库字段名相同,不同需要取别名;配置数据源通过setter方法。 Spring-jdbc手动映射,所以属性名与字段名之间没有要求,写起来就比较麻烦,但是灵活;配置数据源通过构造方法。 纯注解实现业务 什么意思? 1)使用注解和使用xml配置的原则是——自定义的类使用注解;使用别人的框架(工具类)来完成业务就使用xml配置,主要是使用别人的代码,根本没必要也不好修改代码。 2)现在将别人

Today_He的博客 1124

Spring学习第二天,注解的使用和(注解注入/XML和注解注入/XML注入)

spring第二天总结 xml配置需要注意的点 1、配置QueryRunner对象 set方法注入,给QueryRunner生成set方法,通过xml配置QueryRunner进行注入 <!--配置QueryRunner对象--> <bean id="runner" class="org.apache.commons.dbutils.QueryRunner"> <!--构造方法,注入数据源--> <constructor-ar

大脑不能为空 558

54 spring01

spring共四天 第一天:spring框架的概述以及spring中基于XML的IOC配置 第二天:spring中基于注解的IOC和ioc的案例 第三天:spring中的aop和基于XML以及注解的AOP配置 第四天:spring中的JdbcTemlate以及Spring事务控制 1、spring的概述 spring是什么 spring的两大核心 spring的发展历程和优势 spring体系结构...

qq_38664094的博客 470

JavaEE学习日志(八十二): 动态代理dao开发,MyBatis核心配置文件

JavaEE学习日志(八十二) MyBatis: 传统Dao模式, 动态代理模式dao开发, 核心配置文件: 配置文件中的标签和顺序, properties属性, typeAliases属性, mappers属性, 传递的参数类型, 返回值映射。

Sakuraaaaaaa的博客 311

用ESP32和摇杆做个机械臂控制器吧!手把手教你实现双舵机联动

本文详细介绍了如何利用ESP32和摇杆构建一个桌面级机械臂控制器,实现双舵机联动和精准动作映射。从硬件搭建、信号处理到运动控制算法优化,手把手教你完成项目,适合DIY爱好者和工程师参考。

weixin_30823001的博客 363

Spring注解

一、基于注解的IoC 1. 快速入门 需求描述 有dao层:UserDao和UserDaoImpl 有service层:UserService和UserServiceImpl 使用注解配置bean,并注入依赖 需求分析 准备工作:创建Maven项目,导入依赖坐标 编写代码并注解配置: 编写dao层、service层代码,使用注解@Component配置bean:代替xml里的bean标签 使用注解@Autowired依赖注入:代替xml里的property和constructor-arg标签

weixin_41942838的博客 263

SpringDataJpa(五):处理表的一对一、一对多和多对多关系,关联查询

SpringDataJpa: 处理一对一关系: 外键方案, 主键方案。 处理一对多关系, 处理多对多关系, 关联查询。

Sakuraaaaaaa的博客 1211
上一篇: JavaEE学习日志(八十八): spring依赖注入
下一篇: JavaEE学习日志(九十): spring和junit整合,cglib动态代理,springAOP的xml配置和注解配置
隔叶听风
博客等级 码龄8年 93粉丝 202原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值