GVKun编程网logo

faces-config.xml中的注释与托管bean声明

18

本文将分享faces-config.xml中的注释与托管bean声明的详细内容,此外,我们还将为大家带来关于@Configuration中的来声明BeanPostProcessor和BeanFacto

本文将分享faces-config.xml中的注释与托管bean声明的详细内容,此外,我们还将为大家带来关于@Configuration中的来声明BeanPostProcessor和BeanFactoryPostProcessor、android – Phongap config.xml和Cordova config.xml之间有区别吗?、Centos 安装 PHP 5.4.3 报 configure error xml2-config、com.hazelcast.config.InterfacesConfig的实例源码的相关知识,希望对你有所帮助。

本文目录一览:

faces-config.xml中的注释与托管bean声明

faces-config.xml中的注释与托管bean声明

我正在接触JSF 2.0,并对基于新注释的自动装配(在faces-config.xml中没有任何代码的托管bean的声明)有一定的疑问。

就我而言,注释既好又容易,但是可能会出现问题,即在大型系统中一定需要用一个bean替换另一个bean,如果使用了注释,将导致需要删除某些类(或类似的肮脏技巧)
),而可以很容易地将其固定在faces-cofig.xml中。

请分享您的经验。应该考虑什么更方便,为什么?

答案1

小编典典

在JSF
2.0之前,所有bean必须使用XML进行配置。如今,您可以在注释和XML配置之间进行选择。XML配置相当冗长,但是如果要在部署时配置Bean,它可能会很有用。

批注允许快速开发并减少冗余的xml编码。通常,它在很大程度上取决于项目本身。

@Configuration中的来声明BeanPostProcessor和BeanFactoryPostProcessor

@Configuration中的来声明BeanPostProcessor和BeanFactoryPostProcessor

最近在遇到比较一个问题,通常我们在spring中使用@Configuration来注解一个类时,可以同时用Autowire 和@Value 给该配置类自动注入属性值,如下:


@Configuration
public class ConfigA {
   @Autowired
   private Environment environment;
   @Value("${name}")
   private string name;
   @Bean
   public A a() {
       A a = new A();
       a.name = name;
       return a;
   }
}

我们正常情况下都是能自动注入environment和name的,但是当在configration 中如果声明了一个BeanPostProcessor时,如下:

   @Bean
    public MyBeanPostProcessor myBeanPostProcessor(A a) {
        log.info("env=:{}", environment);
        MyBeanPostProcessor myBeanPostProcessor = new MyBeanPostProcessor();
        myBeanPostProcessor.setA(a);
        return myBeanPostProcessor;
    }

你会发现打出来的log env 为null,同时A的name 也为null,这个配置类的 @Autowired和@Value都没有生效。
翻阅spring 的官网,其中有一段小tip,如下

    
Make sure that the dependencies you inject that way are of the simplest kind only. @Configuration classes are processed quite early during the initialization of the context, and forcing a dependency to be injected this way may lead to unexpected early initialization. Whenever possible, resort to parameter-based injection, as in the preceding example.

Also, be particularly careful with BeanPostProcessor and BeanFactoryPostProcessor definitions through @Bean. Those should usually be declared as static @Bean methods, not triggering the instantiation of their containing configuration class. Otherwise, @Autowired and @Value may not work on the configuration class itself, since it is possible to create it as a bean instance earlier than AutowiredAnnotationBeanPostProcessor.

意思就是BeanPostProcessor 和BeanFactoryPostProcessor 会在configuration 本身这个bean初始化之前,可以在spring onrefresh 方法中找到这段代码

image.png

踩坑记录一下。

android – Phongap config.xml和Cordova config.xml之间有区别吗?

android – Phongap config.xml和Cordova config.xml之间有区别吗?

当我正在使用我的Phonegap应用程序时,我注意到Adobe online build的配置和cordova配置(本地)之间存在一些差异.

Cordova:< preference name =“EnableViewportScale”value =“false”/>
Adobe Phonegap:< preference name =“phonegap-version”value =“3.5.0”/>

> Phonegap使用破折号而Cordova则不使用破折号.他们混在一起吗?我可以在本地构建中使用破折号,在在线Adobe构建中使用非破折号吗?
>只要我添加像phonegap-version这样的android-前缀,我可以使用Cordova设置吗?

我也看到:

科尔多瓦:

<platform name="ios">
  <icon src="res/ios/icon-60@3x.png" />
<platform>

PhoneGap的:

<gap:splash gap:platform="android" gap:qualifier="port-ldpi" src="www/res/screen/android/icon-60@3x.png" />

>他们也混在一起吗?或者它是否意味着我必须有一个用于本地构建的配置文件和另一个用于在线构建的配置文件

解决方法:

Phonegap config.xml使用dtd扩展了cordova的config.xml的dtd,允许使用一些特定的标签,如间隙:

您可以使用带有cordova的phonegap dtd,没有任何问题.如果您使用带有phonegap构建的cordova dtd,则可能会忽略某些选项.

Phonegap构建需要一些独立的标签来处理在本地构建时使用CLI完成的事情,例如使用< gap:plugin>安装的插件.

Centos 安装 PHP 5.4.3 报 configure error xml2-config

Centos 安装 PHP 5.4.3 报 configure error xml2-config

参考:http://www.jsjtt.com/xitongyingyong/linux/17.html


Centos 安装 PHP 5.4.3 报 configure error xml2-config not found. please check your libxml2 installation 错误

 

检查是否安装了 libxm 包

[root@rh-linux software]# rpm -qa |grep  libxml2
libxml2-2.6.26-2.1.12
libxml2-python-2.6.26-2.1.12

 

重新安装 libxml2 和 libxml2-devel 包,yum 安装的时候发现新版本会提示更新,需要更新的可以更新,不要跳过就行了。

[root@rh-linux /]# yum install libxml2

[root@rh-linux /]# yum install libxml2-devel -y

 

安装完之后查找 xml2-config 文件是否存在

[root@rh-linux /] # find / -name "xml2-config"
/usr/bin/xml2-config

 

如果存在的话重新安装 php

[root@rh-linux  php-5.4.3]# ./configure

[root@rh-linux  php-5.4.3]# make

[root@rh-linux  php-5.4.3]# make install

安装好 php 后别忘了配置下 php.ini 文件, 

 

[root@rh-linux php-5.4.3]# cp php.ini-production /usr/local/lib/php.ini

也可以直接在 make install 后面加一个编译参数 --with-config-file-path=/usr/local/php/etc 指定自己的 php.ini 路径 然后从源码里面 cp 过去 php.ini 源码里面有个 php.ini-development 和 php.ini-production 如果不是本地调试模式的 选择后者


com.hazelcast.config.InterfacesConfig的实例源码

com.hazelcast.config.InterfacesConfig的实例源码

项目:xm-commons    文件:XmConfigHazelcastConfiguration.java   
private InterfacesConfig buildInterfaces(String interfaces) {
    InterfacesConfig interfacesConfig = new InterfacesConfig();
    interfacesConfig.setEnabled(Boolean.TRUE);

    if (interfaces == null || interfaces.trim().isEmpty()) {
        log.warn("Hazelcast interfaces list is empty");
        return interfacesConfig;
    }

    for (String ip : interfaces.split(",")) {
        if (ip != null && !ip.trim().isEmpty()) {
            interfacesConfig.addInterface(ip);
        }
    }

    return interfacesConfig;
}
项目:xm-ms-config    文件:HazelcastConfiguration.java   
private InterfacesConfig buildInterfaces(String interfaces) {
    InterfacesConfig interfacesConfig = new InterfacesConfig();
    interfacesConfig.setEnabled(Boolean.TRUE);

    if (interfaces == null || interfaces.trim().isEmpty()) {
        log.warn("Hazelcast interfaces list is empty");
        return interfacesConfig;
    }

    for (String ip : interfaces.split(",")) {
        if (ip != null && !ip.trim().isEmpty()) {
            interfacesConfig.addInterface(ip);
        }
    }

    return interfacesConfig;
}
项目:lb-hazelcast    文件:YamlConfigTest.java   
@Test
public void testBuilder() {
    final Config config = new YamlConfigBuilder(getResource()).build();
    assertNotNull(config);

    // Group Config
    assertNotNull(config.getGroupConfig());
    assertEquals("group-name",config.getGroupConfig().getName());
    assertEquals("group-password",config.getGroupConfig().getpassword());

    // Network Config
    final NetworkConfig netCfg = config.getNetworkConfig();

    assertEquals(true,netCfg.isReuseAddress());
    assertEquals(5900,netCfg.getPort());
    assertEquals(false,netCfg.isPortAutoIncrement());
    assertEquals(100,netCfg.getPortCount());
    assertFalse(netCfg.getoutboundPortDeFinitions().isEmpty());
    assertEquals(2,netCfg.getoutboundPortDeFinitions().size());
    assertTrue(netCfg.getoutboundPortDeFinitions().contains("10100"));
    assertTrue(netCfg.getoutboundPortDeFinitions().contains("9000-10000"));
    assertEquals("127.0.0.1",netCfg.getPublicAddress());

    // Multicast Config
    final MulticastConfig mcastCfg = netCfg.getJoin().getMulticastConfig();
    assertEquals(false,mcastCfg.isEnabled());
    assertEquals(false,mcastCfg.isLoopbackModeEnabled());
    assertFalse(mcastCfg.getTrustedInterfaces().isEmpty());
    assertEquals(2,mcastCfg.getTrustedInterfaces().size());
    assertTrue(mcastCfg.getTrustedInterfaces().contains("eth0"));
    assertTrue(mcastCfg.getTrustedInterfaces().contains("eth1"));

    // TcpIp Config
    final TcpIpConfig tcpCfg = netCfg.getJoin().getTcpIpConfig();
    assertEquals(false,tcpCfg.isEnabled());
    assertEquals(10,tcpCfg.getConnectionTimeoutSeconds());
    assertFalse(tcpCfg.getMembers().isEmpty());
    assertEquals(3,tcpCfg.getMembers().size());
    assertTrue(tcpCfg.getMembers().contains("192.168.0.1"));
    assertTrue(tcpCfg.getMembers().contains("192.168.0.2"));
    assertTrue(tcpCfg.getMembers().contains("192.168.0.3"));
    assertEquals("127.0.0.1",tcpCfg.getrequiredMember());

    // Interfaces Config
    final InterfacesConfig ifacesCfg = netCfg.getInterfaces();
    assertEquals(false,ifacesCfg.isEnabled());
    assertEquals(3,ifacesCfg.getInterfaces().size());
    assertTrue(ifacesCfg.getInterfaces().contains("10.3.16.*"));
    assertTrue(ifacesCfg.getInterfaces().contains("10.3.10.4-18"));
    assertTrue(ifacesCfg.getInterfaces().contains("192.168.1.3"));
}
项目:gw2live    文件:HazelcastCache.java   
private HazelcastCache() {
    final AppConfig config = AppConfig.getInstance();
    final Map<String,MapConfig> mapconfigs = new HashMap<>();
    GroupConfig groupconfig = new GroupConfig();
    groupconfig.setName(config.getString("cluster.name","gw2live"));
    groupconfig.setPassword(config.getString("cluster.password","gw2live"));
    final MapConfig mapconfig = new MapConfig();
    mapconfig.getMaxSizeConfig().setMaxSizePolicy(MaxSizePolicy.PER_PARTITION);
    mapconfig.getMaxSizeConfig().setSize(0);
    mapconfig.setevictionPolicy(MapConfig.DEFAULT_evictION_POLICY);
    mapconfig.setBackupCount(1);
    mapconfigs.put("*-cache",mapconfig);
    final NetworkConfig nwconfig = new NetworkConfig();
    if(config.containsKey("cluster.interface")) {
        final InterfacesConfig interfaces = new InterfacesConfig();
        interfaces.addInterface(config.getString("cluster.interface"));
        interfaces.setEnabled(true);
        nwconfig.setInterfaces(interfaces);
    }
    nwconfig.setPort(config.getInteger("cluster.port",5801));
    nwconfig.setPortAutoIncrement(true);
    final MulticastConfig mcconfig = new MulticastConfig();
    mcconfig.setEnabled(true);
    mcconfig.setMulticastGroup(config.getString("cluster.multicast.group","224.2.2.3"));
    mcconfig.setMulticastPort(config.getInteger("cluster.multicast.port",58011));
    mcconfig.setMulticastTimetoLive(MulticastConfig.DEFAULT_MULTICAST_TTL);
    mcconfig.setMulticastTimeoutSeconds(MulticastConfig.DEFAULT_MULTICAST_TIMEOUT_SECONDS);
    final JoinConfig join = new JoinConfig();
    join.setMulticastConfig(mcconfig);
    nwconfig.setJoin(join);
    final ExecutorConfig execconfig = new ExecutorConfig();
    execconfig.setName("default");
    execconfig.setPoolSize(4);
    execconfig.setQueueCapacity(100);
    final Map<String,ExecutorConfig> execmap = new HashMap<>();
    execmap.put("default",execconfig);
    final Config hconfig = new Config();
    hconfig.setInstanceName("gw2live");
    hconfig.setGroupConfig(groupconfig);
    hconfig.setMapConfigs(mapconfigs);
    hconfig.setNetworkConfig(nwconfig);
    hconfig.setExecutorConfigs(execmap);
    hconfig.setProperty("hazelcast.shutdownhook.enabled","false");
    hconfig.setProperty("hazelcast.wait.seconds.before.join","0");
    hconfig.setProperty("hazelcast.rest.enabled","false");
    hconfig.setProperty("hazelcast.memcache.enabled","false");
    hconfig.setProperty("hazelcast.mancenter.enabled","false");
    hconfig.setProperty("hazelcast.logging.type","none");
    cache = Hazelcast.newHazelcastInstance(hconfig);

    LOG.debug("Hazelcast initialized");
}

关于faces-config.xml中的注释与托管bean声明的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于@Configuration中的来声明BeanPostProcessor和BeanFactoryPostProcessor、android – Phongap config.xml和Cordova config.xml之间有区别吗?、Centos 安装 PHP 5.4.3 报 configure error xml2-config、com.hazelcast.config.InterfacesConfig的实例源码的相关知识,请在本站寻找。

本文标签: