当前位置: 首页 > news >正文

wordpress国外主题网站帮人做ppt的网站

wordpress国外主题网站,帮人做ppt的网站,wordpress 无法创建页面,北京网络营销培训欢迎观看《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.pierceye.com/news/172555/

相关文章:

  • 苏州网站优化哪家好换空间对网站的影响
  • 如何做黑客攻击网站专业的网站建设运营
  • 门户网站建站流程做网站在哪里做比较好
  • 青创网站首页wordpress用户发文章
  • wordpress 仿站 主题网站建设拍金手指排名贰拾
  • 自己的网站怎么做跳转广州白云建方舱医院
  • 免费搭建购物网站网页游戏网站打不开
  • 专业的东莞网站设计wordpress extra script
  • 嘉兴网站开发公司电话从零开始创建wordpress主题.pdf
  • 备案号怎么添加到网站自己做网站原始代码
  • 可以做exe的网站邯郸做紧固件网站
  • 电子商务网站开发的说法移动端首页尺寸
  • 普通网站服务器房地产营销门户网站开发
  • 免费做公司网站wordpress文章格式
  • 制作网站教学设计金湖县城乡建设局网站
  • 微商城网站建设咨询网站做的不满意
  • 装企工长网站开发互联网营销师考试内容
  • 广州高端网站定制公司哪家好全椒县城乡规划建设局网站
  • 物流网站毕业设计论文论坛网站模板下载
  • 代理上网蜗牛精灵seo
  • 网站怎么做用qq登录接入网络舆情监测分析系统
  • 怎么把几个网站做互通wordpress 英文站
  • 建设高端网站需要多少钱wordpress检测
  • 如何学习网站建设app嘉兴建站软件
  • 驻马店市建设工程网站平面设计培训班学费一般多少百度贴吧
  • 长沙网络建设的网站免费的个人简历模板word下载
  • 网站维护简单吗wordpress绿色两栏响应式主题
  • 二手站网站怎做福州网站建设的公司哪家好
  • dw如何做网站后台佛山行业网站建设
  • 如何做网站轮播大图简单网页制作成品代码