网站实名认证怎么做网站分析怎么做的

news/2025/10/4 16:02:24/文章来源:
网站实名认证怎么做,网站分析怎么做的,者珠海市建设局网站,网络营销的渠道有哪些欢迎观看《Spring Framework实战》视频教程 方法注入 在大多数应用场景中#xff0c;容器中的大多数bean都是单例#xff08;singletons#xff09;的。当单例bean需要与另一个单例bean协作或非单例bean需与另一非单例bean协作时#xff0c;通常通过将一个bean定义为另一个…欢迎观看《Spring Framework实战》视频教程 方法注入 在大多数应用场景中容器中的大多数bean都是单例singletons的。当单例bean需要与另一个单例bean协作或非单例bean需与另一非单例bean协作时通常通过将一个bean定义为另一个bean的属性来处理依赖关系。当bean的生命周期不同时就会出现问题。假设单例bean A需要使用非单例prototypebean B可能是在A的每次方法调用时。容器只创建单例bean A一次因此只有一次机会设置属性。容器不能在每次需要bean B时为bean A提供bean B的新实例。 一个解决方案是放弃一些控制反转。您可以通过实现ApplicationContextAware接口并在每次bean A需要时对容器进行getBean“B”调用请求通常是新的bean B实例使bean A知道容器。 以下示例显示了这种方法 Java package org.examples; import java.util.Map; public class Command {     private Map state;     public Map getState() {         return state;     }     public void setState(Map state) {         this.state state;     }     public String execute() {         return Command this execute, state this.state;     } } package org.examples; import java.util.Map; /**  * 当bean的生命周期不同时就会出现问题。  */ public class CommandManager {     public Command command;     public Command getCommand() {         return command;     }     public void setCommand(Command command) {         this.command command;     }     public String process(Map State) {         // 在希望是全新的Command实例上设置状态         this.command.setState(State);         return this.command.execute();     } } bean idcommandManager classorg.examples.CommandManager scopesingleton     !-- collaborators and configuration for this bean go here --     property namecommand refcommand/ /bean bean idcommand classorg.examples.Command scopeprototype     !-- collaborators and configuration for this bean go here --     property namestate         map             entry keystate1 valueaaa/             entry keystate2 valuebbb/             entry keystate3 valueccc/         /map     /property /bean CommandManager commandManager (CommandManager) context.getBean(CommandManager.class); Map map1 new HashMap(); map1.put(state, state111); System.out.println(commandManager.process(map1)); Map map2 new HashMap(); map2.put(state, state222); System.out.println(commandManager.process(map2)); package org.examples; // Spring-API imports import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import java.util.Map; /**  * A class that uses a stateful Command-style class to perform  * some processing.  * p  * 您可以通过实现ApplicationContextAware接口  * 并在每次bean A需要时对容器进行getBean“B”调用  * 请求通常是新的bean B实例使bean A知道容器。  */ public class CommandManager implements ApplicationContextAware {     private ApplicationContext applicationContext;     public String process(Map commandState) {         // grab a new instance of the appropriate Command         // 获取相应命令的新实例         Command command createCommand();         // set the state on the (hopefully brand new) Command instance         // 在希望是全新的Command实例上设置状态         command.setState(commandState);         return command.execute();     }     protected Command createCommand() {         // notice the Spring API dependency!         return this.applicationContext.getBean(command, Command.class);     }     public void setApplicationContext(             ApplicationContext applicationContext) throws BeansException {         this.applicationContext applicationContext;     } } bean idcommandManager classorg.examples.CommandManager scopesingleton     !-- collaborators and configuration for this bean go here -- /bean bean idcommand classorg.examples.Command scopeprototype     !-- collaborators and configuration for this bean go here --     property namestate         map             entry keystate1 valueaaa/             entry keystate2 valuebbb/             entry keystate3 valueccc/         /map     /property /bean 前面的内容是不可取的因为业务代码意识到并耦合到Spring Framework。方法注入是Spring IoC容器的一个稍微高级的功能可以让你干净利落地处理这个用例。 你可以在这篇博客文章中关于方法注入的动机。 查找方法注入 查找方法注入是容器覆盖容器管理bean上的方法并返回容器中另一个命名bean的查找结果的能力。查找通常涉及一个原型bean如前一节所述的场景。Spring Framework通过使用CGLIB库中的字节码生成来动态生成覆盖该方法的子类从而实现了这种方法注入。 为了使这种动态子类工作Spring bean容器子类的类不能是final的要重写的方法也不能是final的。对具有抽象方法的类进行单元测试需要您自己对类进行子类化并提供抽象方法的存根实现。组件扫描也需要具体的方法这需要具体的类来拾取。另一个关键限制是查找方法不适用于工厂方法特别是不适用于配置类中的Bean方法因为在这种情况下容器不负责创建实例因此无法动态创建运行时生成的子类。 在前面代码片段中的CommandManager类的情况下Spring容器动态覆盖createCommand方法的实现。CommandManager类没有任何Spring依赖项如重新编写的示例所示 Java package org.examples; // no more Spring imports! 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(); } 在包含要注入的方法在本例中为CommandManager的客户端类中要注入的方式需要以下形式的签名 public|protected [abstract] return-type theMethodName(no-arguments); 如果方法是抽象的则动态生成的子类实现该方法。否则动态生成的子类会覆盖原始类中定义的具体方法。考虑以下示例 !-- a stateful bean deployed as a prototype (non-singleton) -- bean idmyCommand classorg.examples.AsyncCommand scopeprototype !-- inject dependencies here as required -- /bean !-- commandManager uses myCommand prototype bean -- bean idcommandManager classorg.examples.CommandManager lookup-method namecreateCommand beanmyCommand/ /bean 标识为commandManager的bean在需要myCommand bean的新实例时调用自己的createCommand方法。如果确实需要您必须小心地将myCommand bean部署为原型。如果它是单例则每次都会返回相同的myCommand bean实例。 或者在基于注释的组件模型中您可以通过lookup注释声明查找方法如下例所示 Java public abstract class CommandManager { public Object process(Object commandState) { Command command createCommand(); command.setState(commandState); return command.execute(); } Lookup(myCommand) protected abstract Command createCommand(); } 或者更习惯地说你可以依靠目标bean根据查找方法的声明返回类型进行解析 Java public abstract class CommandManager { public Object process(Object commandState) { Command command createCommand(); command.setState(commandState); return command.execute(); } Lookup protected abstract Command createCommand(); } 请注意您通常应该使用具体的存根实现声明此类带注释的查找方法以便它们与Spring的组件扫描规则兼容默认情况下抽象类会被忽略。此限制不适用于显式注册或显式导入的bean类。 访问不同作用域的目标bean的另一种方法是ObjectFactory/Provider注入点。请参阅作为依赖关系的作用域Bean。 您可能还会发现ServiceLocatorFactoryBean在org.springframework.beans.factory.config包中很有用。 任意方法替换 一种不如查找方法注入有用的方法注入形式是能够用另一种方法实现替换托管bean中的任意方法。您可以安全地跳过本节的其余部分直到您真正需要此功能。 使用基于XML的配置元数据您可以使用替换的方法元素将已部署bean的现有方法实现替换为另一个方法实现。考虑以下类它有一个我们想要重写的名为computeValue的方法 Java public class MyValueCalculator { public String computeValue(String input) { // some real code... } // some other methods... } 一个实现org.springframework.beans.factory.support的类。MethodReplacer接口提供了新的方法定义如下例所示 Java /** * meant to be used to override the existing computeValue(String) * implementation in MyValueCalculator */ public class ReplacementComputeValue implements MethodReplacer { public Object reimplement(Object o, Method m, Object[] args) throws Throwable { // get the input value, work with it, and return a computed result String input (String) args[0]; ... return ...; } } 部署原始类并指定方法重写的bean定义类似于以下示例 bean idmyValueCalculator classx.y.z.MyValueCalculator !-- arbitrary method replacement -- replaced-method namecomputeValue replacerreplacementComputeValue arg-typeString/arg-type /replaced-method /bean bean idreplacementComputeValue classa.b.c.ReplacementComputeValue/ 您可以在replaced method/元素中使用一个或多个arg type/元素来指示被重写方法的方法签名。只有当方法重载并且类中存在多个变量时才需要参数的签名。为方便起见参数的类型字符串可以是完全限定类型名称的子字符串。例如以下所有匹配项 java.lang.String : java.lang.String String Str 因为参数的数量通常足以区分每种可能的选择所以这个快捷方式可以节省大量的输入只让你输入与参数类型匹配的最短字符串。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/927309.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

400网站建设价格信誉好的常州做网站

"Everything" 是一个 Windows 平台上的免费软件,它是一款功能强大的本地文件搜索工具。它允许用户在计算机上快速而准确地搜索文件和文件夹。以下是一些 "Everything" 的主要特点: 实时搜索: "Everything" 提供…

dw5怎样做网站备案号怎么添加到网站

动态定时任务 原理 采用定时任务线程池ThreadPoolTaskScheduler来实现定时任务。动态定时任务就是可以配置的,而不是写死在代码中。所以我们要将其写入到数据库中,然后暴露接口就可以进行配置比如创建、启动、结束任务。 数据库脚本 DROP TABLE IF EXIS…

帮人做网站赚钱吗南京江宁网站制作

HTML 列表中的dl,dt,dd,ul,li,ol区别及应用 HTML 列表中的dl,dt,dd,ul,li,ol区别及应用 工具/原料 html&#xff0c;dw软件方法/步骤 1无序列表 无序列表是一个项目的列表&#xff0c;此列项目使用粗体圆点&#xff08;典型的小黑圆圈&#xff09;进行标记。 无序列表始于 <…

实用指南:基于Selenium+Python的web自动化测试框架

实用指南:基于Selenium+Python的web自动化测试框架pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas"…

实施网站推广的最终目的是startup wordpress

HTML学习笔记 day one Chapter one 网站开发基础 1.2网站的基本架构 网站的基本要素&#xff1a;内容&#xff0c;页面&#xff0c;超链接 动态网页和静态网页的区别在于&#xff1a;动态网页会自动更新&#xff0c;后缀名是.asp或者.aspx;而静态网页不会自动更新&#xff0c…

南阳网站开发凡科网做网站教程

吴恩达《机器学习》学习笔记七——逻辑回归&#xff08;二分类&#xff09;代码一、无正则项的逻辑回归1.问题描述2.导入模块3.准备数据4.假设函数5.代价函数6.梯度下降7.拟合参数8.用训练集预测和验证9.寻找决策边界二、正则化逻辑回归1.准备数据2.特征映射3.正则化代价函数4.…

适合新手的PPT模板网站,简单操作但效果好!

你是不是也有过这样的经历?明天就要汇报了,今天还在对着空白PPT发呆,找遍全网模板不是收费就是丑到没法用,最后只能硬着头皮交差然后被老板怼?别慌,作为从业8年的PPT设计师,我今天就把压箱底的宝藏网站和私藏技…

2025多校冲刺CSP模拟赛2 总结

比赛:2025多校冲刺CSP模拟赛2 日期:\(25.10.04\),场地:\(\text{accoder}\),排名:\(45/137\) 估分:\(100+([0,100])+20+45=165+[0,100]\) 终分:\(100 + 55 + 20 + 75 =250\) 失分 今天的比赛真的太难了,\(T_2\…

pip list 可以查到某个包,但是,import某个包,出现 ModuleNotFoundError: No module named

pip list 可以查到某个包,但是,import某个包,出现 ModuleNotFoundError: No module named (segmamba) [root@ibiomed ~]# pip list | grep gen gensim 4.3.3 (segmamba) [root@ibiomed ~]# pytho…

无人机常用的几种飞行模式

无人机常用的几种飞行模式地址: https://www.bilibili.com/video/BV12u4y1d7n6本博客是博主个人学习时的一些记录,不保证是为原创,个别文章加入了转载的源地址,还有个别文章是汇总网上多份资料所成,在这之中也必有…

详细介绍:conda使用指南

详细介绍:conda使用指南pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", &q…

VMProtect 是什么

VMProtect 是什么VMProtect 是一种 软件保护工具(Software Protection / Code Obfuscation),主要用于防止程序被破解、逆向或篡改。开发者可以用它保护 Windows、macOS、Linux 等平台上的可执行程序。它的核心是 虚…

电影网站做静态是不是好一些北京网页设计公司兴田德润可以吗

题目链接 Solution 可以考虑到如果知道环内一点的身份,如果凶手在其中就查出来了,同时不会有危险. 那么对警察造成威胁的就是那些身份不明且不能从其他点转移过来的点. 那么大部答案就是缩完点之后入度为 \(0\) 的联通块数量. 但是,会有特殊情况: 如图,我们就只要查 \(2\) 或者…

自动驾驶中的传感器工艺56——USS(2)

pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consolas", "Monaco", "Courier New", …

探索 Docker/K8s 部署 MySQL 的创新实践与优化技巧 - 详解

探索 Docker/K8s 部署 MySQL 的创新实践与优化技巧 - 详解pre { white-space: pre !important; word-wrap: normal !important; overflow-x: auto !important; display: block !important; font-family: "Consola…

基于Registry搭建docker加速镜像服务

基于 Registry 搭建 Docker 加速镜像服务旨在解决 docker.io 网络访问不畅及多服务器拉取镜像时外网负载过重的问题。背景场景:docker.io网络访问不通畅,服务器难以拉取镜像 多个服务器拉取相同镜像时,外网连接负载…

mssql 无锁读取

无锁读取,无阻塞,速度快nolock 读未提交,产生脏读RCSI 开启RCSI,读取锁定数据 的最新提交版本 。无脏读,数据读一致性。

2025年四川大学计算机学院专硕考研经验分享

初试 总分:22408,360+ 时间规划(大概安排) 我是从24年3月也就是开学开始准备考研的,上午10点去图书馆看一个多小时,下午2点开始看到5点半,晚上7点半开始看到9点半,学6休1。开始的时候就学数学,看张宇18讲和记…

基础数学拾遗

目录余弦定理 余弦定理 对于任意一个三角形: \[a^2 = b^2 + c^2 - 2bc * cosA \]任意一边的平方,等于另外两边的平方和,减去2倍这两边与它们夹角余弦值的乘积。