spring文档阅读笔记(一)

本文介绍了Spring框架中Bean的各种配置方式,包括传统声明式、c-namespace声明式、依赖注入、自动装配、作用域设定等,并展示了如何实现ApplicationContextAware和BeanNameAware接口。
1. p-namespace
<bean name = "john-modern" class = "com.example.Person" p:name = "John Doe" p:spouse-ref = "jane" />

2.c-namespce
<!-- traditional declaration --> <bean id = "foo" class = "x.y.Foo" > <constructor-arg ref = "bar" /> <constructor-arg ref = "baz" /> <constructor-arg value = "foo@bar.com" /> </bean> <!-- c-namespace declaration --> <bean id = "foo" class = "x.y.Foo" c:bar-ref = "bar" c:baz- ref = "baz" c:email = "foo@bar.com" />

3. depends-on
<bean id = "beanOne" class = "ExampleBean" depends-on = "manager" /> <bean id = "manager" class = "ManagerBean" />
表示manager要在beanOne之前初始化

4. beans标签设置default-autowire参数
<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" default -autowire= "byName" >

默认自动装配
< bean id = "student" class = "com.haiwi.spring.Student" autowire = "byName" >

5.方法注入

实现 ApplicationContextAware接口,通过容器返回需要的bean
public class CommandManager implements ApplicationContextAware

6.查找方法注入

编写抽象类

public abstract class CommandManager { public Object process(Object commandState) { // grab a new instance of the appropriate Command interface Command command = createCommand(); // set the state on the (hopefully brand new) Command instance command.setState(commandState); return command.execute(); } // okay... but where is the implementation of this method? protected abstract Command createCommand();}

配置抽象方法

<bean id = "myCommand" class = "fiona.apple.AsyncCommand" scope = "prototype" > <!-- inject dependencies here as required --> </bean> <!-- commandProcessor uses statefulCommandHelper --> <bean id = "commandManager" class = "fiona.apple.CommandManager" > <lookup-method name = "createCommand" bean = "myCommand" /> </bean>

7.bean作用域

8.实现 ApplicationContextAware 接口能获取到spring容器
public interface ApplicationContextAware { void setApplicationContext(ApplicationContext applicationContext) throws BeansException;}

9.实现 BeanNameAware可以获取bean的名称

  1. public class MyBeanNameAware implements BeanNameAware{  
  2.   
  3.     public void setBeanName(String name) {  
  4.         System.out.println("my name is "+name);  
  5.     }  
  6.       
  7.       
  8.   
  9. }  

源码直接下载地址: https://pan.quark.cn/s/d280357b18e5 在网页构建领域中,HTML5被视为当代网页工程的基础规范,其问世显著增强了页面的视觉表现力与用户互动性。本工程致力于运用HTML5技术开发一个电视剧信息展示页面,目的是呈现诸如剧名、演员构成、故事梗概等电视剧关键资料。接下来将深入阐释如何借助HTML5的结构化组件和样式管理功能达成此项目目标。 我们必须掌握HTML5的核心框架。一个规范的HTML5文档般包含`<!DOCTYPE html>`声明、`<html>`根标记、`<head>`头部标记和`<body>`主体标记。在头部区域,可以配置网页的基本元数据,例如字符集设定、页面标题等。在主体部分,将具体构建电视剧信息列表的内容。 电视剧展示页面通常包含多个条目,每个条目对应部电视剧。HTML5中的`<section>`标记用于内容模块化,适合表示单个电视剧的详细信息区域。每个`<section>`内部,可使用`<h2>`标题标记显示剧名,`<img>`图像标记插入宣传剧照,`<p>`段落标记呈现剧情介绍,而`<ul>`无序列表与`<li>`列表项标记则用于罗列演员阵容。 为了优化页面布局,需要借助CSS(层叠样式表)进行样式管理。HTML5引入了创新的CSS选择器与布局模型,例如Flexbox和Grid,使页面布局更加灵活多变。在此场景下,可以利用Flexbox为电视剧信息列表实现自适应布局,保障在不同设备尺寸下均能呈现理想视觉效果。具体操作时,可将`<section>`标记设定为Flex容器,通过`display: flex;`属性,并运用`justify-content`和`align-items`属性调整子元素的对...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值