我已经配置了Apache公共资源来从xml读取数据。我的配置文件是
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.configuration2.spring.ConfigurationPropertySource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;
@Configuration
public class PropertiesConfig {
@Autowired
private ConfigurableEnvironment env;
@Autowired
public void propertySourcesPlaceholderConfigurer(ConfigurableEnvironment env) throws ConfigurationException {
ConfigurationPropertySource configurationPropertySource = new ConfigurationPropertySource("xml configuration",
new Configurations().xml("config.xml"));
env.getPropertySources().addLast(configurationPropertySource);
}
}
我的config.xml是
<?xml version="1.0" encoding="ISO-8859-1" ?>
<configuration>
<paths>
<path name="data" value="getData" />
<path name="property" value="getProperties" />
</paths>
</configuration>
在我的控制器中,我将环境称为
import org.springframework.core.env.Environment;
@Autowired
private Environment env;
如何解析控制器中的xml?需要获取xml中“路径”节点的特定值