<tfoot id='Dvmi4'></tfoot>
  • <i id='Dvmi4'><tr id='Dvmi4'><dt id='Dvmi4'><q id='Dvmi4'><span id='Dvmi4'><b id='Dvmi4'><form id='Dvmi4'><ins id='Dvmi4'></ins><ul id='Dvmi4'></ul><sub id='Dvmi4'></sub></form><legend id='Dvmi4'></legend><bdo id='Dvmi4'><pre id='Dvmi4'><center id='Dvmi4'></center></pre></bdo></b><th id='Dvmi4'></th></span></q></dt></tr></i><div id='Dvmi4'><tfoot id='Dvmi4'></tfoot><dl id='Dvmi4'><fieldset id='Dvmi4'></fieldset></dl></div>
    1. <legend id='Dvmi4'><style id='Dvmi4'><dir id='Dvmi4'><q id='Dvmi4'></q></dir></style></legend>

    2. <small id='Dvmi4'></small><noframes id='Dvmi4'>

          <bdo id='Dvmi4'></bdo><ul id='Dvmi4'></ul>

        JSF 2 使用 @ManagedProperty 注入 Spring bean/service 而没

        时间:2023-07-26
        <legend id='DiD5I'><style id='DiD5I'><dir id='DiD5I'><q id='DiD5I'></q></dir></style></legend>

          • <bdo id='DiD5I'></bdo><ul id='DiD5I'></ul>
              1. <small id='DiD5I'></small><noframes id='DiD5I'>

                • <tfoot id='DiD5I'></tfoot>
                    <tbody id='DiD5I'></tbody>
                  <i id='DiD5I'><tr id='DiD5I'><dt id='DiD5I'><q id='DiD5I'><span id='DiD5I'><b id='DiD5I'><form id='DiD5I'><ins id='DiD5I'></ins><ul id='DiD5I'></ul><sub id='DiD5I'></sub></form><legend id='DiD5I'></legend><bdo id='DiD5I'><pre id='DiD5I'><center id='DiD5I'></center></pre></bdo></b><th id='DiD5I'></th></span></q></dt></tr></i><div id='DiD5I'><tfoot id='DiD5I'></tfoot><dl id='DiD5I'><fieldset id='DiD5I'></fieldset></dl></div>

                  本文介绍了JSF 2 使用 @ManagedProperty 注入 Spring bean/service 而没有 xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想使用 jsf 注释和一些 spring将 spring bean/服务注入 jsf 托管 bean 的注释.(在 jsf bean 上我只想使用 jsf 注释)我不想使用像 @named/@inject 这样的注解.

                  I would like to use jsf annotations and some spring annotations to inject a spring bean/service into a jsf managed bean. (on the jsf bean i only want to use jsf annotations) I dont want to use annotations like @named / @inject.

                  我试图在网上找到解决方案,但没有任何运气.

                  I have tried to find a solution on the net but without any luck.

                  例子

                  @ManagedBean
                  @ViewScoped 
                  public class MyBean {
                  
                      @ManagedProperty(value = "#{mySpringBean}")
                      private MySpringBean mySpringBean;
                  
                      public void setMySpringBean(MySpringBean mySpringBean) {
                          this.mySpringBean = mySpringBean;
                      }
                  
                      public void doSomething() {
                      //do something with mySpringBean
                      }
                  }
                  

                  在不使用 xml 的情况下,这样的事情是否可行.例如,我不想使用类似的东西

                  Is something like this possible without the use of xml. For example, I would NOT like to use something like

                  FacesContextUtils.getWebApplicationContext(context).getBean("MySpringBean");
                  

                  或在 faces-config.xml

                  <managed-bean>
                      <managed-bean-name>myBean</managed-bean-name>
                      <managed-bean-class>com.mytest.MyBean</managed-bean-class>
                      <managed-bean-scope>view</managed-bean-scope>
                      <managed-property>
                          <property-name>mySpringBean</property-name>
                          <value>#{mySpringBean}</value>
                      </managed-property>
                  </managed-bean>
                  

                  上面的内容是否可能有注释和没有注释定义所有 jsf beans/properties 和 spring beans/properties配置 xml 文件中的每个 bean?

                  Is something like the above possible with annotations and without defining all the jsf beans/properties and the spring beans/properties for every bean in the config xml files?

                  推荐答案

                  如果你已经有了 Spring 容器,为什么不使用它的 @Autowired 注解.为此,请按照 Boni 的建议更新您的 faces-config.xml.然后在此之后将这些侦听器添加到您的 web.xml 中

                  If you already have Spring container why not use its @Autowired annotation. For that, Update your faces-config.xml as suggested by Boni. Then add these listeners to your web.xml after this

                  <context-param>
                      <param-name>contextConfigLocation</param-name>
                      <param-value>/WEB-INF/applicationContext.xml</param-value>
                  </context-param>
                  
                  <listener>
                    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
                  </listener>
                  
                  <listener>
                    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
                  </listener>
                  

                  然后将这些添加到您的 applicationContext.xml

                  Then add these to your applicationContext.xml

                  <context:component-scan base-package="com.examples" />
                  

                  现在您可以使用 Spring 注释,您的 bean 将是这样的:

                  Now you can use Spring annotations and your bean will be something like this:

                  package com.examples;
                  @Component
                  @Scope(value="request")
                  public class MyBean {
                      @Autowired
                      private MySpringBeanClass mySpringBean;
                  }
                  

                  使用 @Service 注释您的 MySpringBeanClass

                  Annotate your MySpringBeanClass with @Service

                  另见:

                  • @Scope("request") 不起作用

                  这篇关于JSF 2 使用 @ManagedProperty 注入 Spring bean/service 而没有 xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在注解中使用数组常量 下一篇:Spring MVC:&lt;context:component-scan&gt; 之间的区别

                  相关文章

                  最新文章

                • <legend id='rtRpU'><style id='rtRpU'><dir id='rtRpU'><q id='rtRpU'></q></dir></style></legend>

                      <tfoot id='rtRpU'></tfoot>

                      <i id='rtRpU'><tr id='rtRpU'><dt id='rtRpU'><q id='rtRpU'><span id='rtRpU'><b id='rtRpU'><form id='rtRpU'><ins id='rtRpU'></ins><ul id='rtRpU'></ul><sub id='rtRpU'></sub></form><legend id='rtRpU'></legend><bdo id='rtRpU'><pre id='rtRpU'><center id='rtRpU'></center></pre></bdo></b><th id='rtRpU'></th></span></q></dt></tr></i><div id='rtRpU'><tfoot id='rtRpU'></tfoot><dl id='rtRpU'><fieldset id='rtRpU'></fieldset></dl></div>
                      • <bdo id='rtRpU'></bdo><ul id='rtRpU'></ul>
                    1. <small id='rtRpU'></small><noframes id='rtRpU'>