Spring static variable injection assignment, static method invocation, static statement block __spring

Source: Internet
Author: User

For static method calls, static variables are assigned values. Spring provides a class:

Org.springframework.beans.factory.config.MethodInvokingFactoryBean

How to use the method:
Configuring in the Spring configuration file:

<bean class= "Org.springframework.beans.factory.config.MethodInvokingFactoryBean" >
     <property name= " Staticmethod "value=" Com.sojson.core.domain.DomainDistribution.setDomainInfo "/>
     <property name=" Arguments ">
        <array>
            <value>{" Convert ":" Word2spell,cn2spark,pingindic,low2up,fullhalf "} </value>
            <value>{"color": "Cj,img,online,page,select,use,web"}</value>
        </array>
     </property>
</bean>
Name= "Staticmethod": fixed wording, as the name suggests is static method. Value= "Com.sojson.core.domain.DomainDistribution.setDomainInfo": The corresponding static method, Com.sojson.core.domain.DomainDistribution is the full path of the class, and Setdomaininfo is the static method name. Name= "Arguments": parameters, and my array is because I'm going to inject an array, which is actually a JSON array.

corresponding Java

Package com.sojson.core.domain;
Import Java.util.LinkedHashMap;
Import Java.util.Map;
Import Java.util.Set;
public class Domaindistribution {
    static String x;
    Static statement block
    static{
        x = "Test static statement block." ";
    }
    public static map<string,set<string>> Domainmap = new linkedhashmap<string,set<string>> ();
    /**
     * Static Call method Test
     * @param domaininfo
    /public static void Setdomaininfo (string[) domaininfo) { For

        (String json:domaininfo) {
            System.out.println (JSON);
        }
    }

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.