File: context.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
10
-10
10
File: Main.java
import java.beans.PropertyEditorSupport;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.CustomEditorConfigurer;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
public class Main {
public static void main(String[] args) throws Exception {
ConfigurableListableBeanFactory factory = new XmlBeanFactory(new ClassPathResource(
"context.xml"));
CustomEditorConfigurer configurer = (CustomEditorConfigurer) factory
.getBean("customEditorConfigurer");
configurer.postProcessBeanFactory(factory);
CustomEditorDemo bean = (CustomEditorDemo) factory.getBean("exampleBean");
System.out.println(bean.sum());
}
}
class ComplexPropertyEditor extends PropertyEditorSupport {
public void setAsText(String s) throws IllegalArgumentException {
Double re = Double.parseDouble(s);
}
}
class CustomEditorDemo {
private double[] values;
private double result;
public double sum() {
for (double value : this.values) {
result = result + value;
}
return result;
}
public void setValues(double[] values) {
this.values = values;
}
}
Spring-ConfigurableListableBeanFactory.zip( 2,600 k)