1.在test环境中获取xml:
@Test
public void testFindUserById() throws Exception{
String resource = "SqlMapConfig.xml";
//通过流将核心配置文件读取进来
InputStream inputStream = Resources.getResourceAsStream(resource);
2.在非spring的xml文件中
<configuration>
<properties resource="db.properties"></properties>
3.springmvc中获取资源文件中的值
a. springmvc.xml中
<!-- 引入字典资源文件 -->
<context:property-placeholder location="classpath:resource.properties"/>
b. CustomerController 中
@Controller
@RequestMapping("/customer")
public class CustomerController {
@Autowired
private CustomerService customerService;
@Value("${customer.dict.source}")
private String source;