摘要:
Spring全注解开发 全注解开发就是不再使用spring配置文件了,写一个配置类来代替配置文件。 package com.atguigu.spring6.config; import org.springframework.context.annotation.ComponentScan; imp 阅读全文
posted @ 2023-02-06 16:41
LaViez
阅读(31)
评论(0)
推荐(0)
摘要:
@Resource注入 @Resource注解也可以完成属性注入。那它和@Autowired注解有什么区别? @Resource注解是JDK扩展包中的,也就是说属于JDK的一部分。所以该注解是标准注解,更加具有通用性。(JSR-250标准中制定的注解类型。JSR是Java规范提案。) @Autowi 阅读全文
posted @ 2023-02-06 16:36
LaViez
阅读(1373)
评论(0)
推荐(0)
摘要:
@Autowired注入 单独使用@Autowired注解,默认根据类型装配。【默认是byType】 查看源码: package org.springframework.beans.factory.annotation; import java.lang.annotation.Documented; 阅读全文
posted @ 2023-02-06 16:12
LaViez
阅读(121)
评论(0)
推荐(0)
摘要:
Annotation 从 Java 5 开始,Java 增加了对注解(Annotation)的支持,它是代码中的一种特殊标记,可以在编译、类加载和运行时被读取,执行相应的处理。开发人员可以通过注解在不改变原有代码和逻辑的情况下,在源代码中嵌入补充信息。 Spring 从 2.5 版本开始提供了对注解 阅读全文
posted @ 2023-02-06 15:32
LaViez
阅读(32)
评论(0)
推荐(0)
摘要:
基于xml自动装配 自动装配: 根据指定的策略,在IOC容器中匹配某一个bean,自动为指定的bean中所依赖的类类型或接口类型属性赋值 ①场景模拟 创建类UserController package com.atguigu.spring6.autowire.controller public cl 阅读全文
posted @ 2023-02-06 15:25
LaViez
阅读(26)
评论(0)
推荐(0)
摘要:
FactoryBean ①简介 FactoryBean是Spring提供的一种整合第三方框架的常用机制。和普通的bean不同,配置一个FactoryBean类型的bean,在获取bean的时候得到的并不是class属性中配置的这个类的对象,而是getObject()方法的返回值。通过这种机制,Spr 阅读全文
posted @ 2023-02-06 15:08
LaViez
阅读(21)
评论(0)
推荐(0)
摘要:
②修改类User public class User { private Integer id; private String username; private String password; private Integer age; public User() { System.out.pri 阅读全文
posted @ 2023-02-06 15:08
LaViez
阅读(22)
评论(0)
推荐(0)
摘要:
bean的作用域 概念 在Spring中可以通过配置bean标签的scope属性来指定bean的作用域范围,各取值含义参加下表: | 取值 | 含义 | 创建对象的时机 | | | | | | singleton(默认) | 在IOC容器中,这个bean的对象始终为单实例 | IOC容器初始化时 | 阅读全文
posted @ 2023-02-06 11:36
LaViez
阅读(65)
评论(0)
推荐(0)
摘要:
不使用外部文件注入方法时,如何连接数据库 @Test public void demo01(){ DruidDataSource dataSource = new DruidDataSource(); dataSource.setUrl("jdbc:mysql://localhost:3306/sp 阅读全文
posted @ 2023-02-06 11:06
LaViez
阅读(27)
评论(0)
推荐(0)
摘要:
p命名空间 引入p命名空间 xmlns:p="http://www.springframework.org/schema/p" <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/sc 阅读全文
posted @ 2023-02-06 11:04
LaViez
阅读(30)
评论(0)
推荐(0)

浙公网安备 33010602011771号