Spring MVC应用程序上的外部属性文件配置

时间:2016-05-25 13:15:21

标签: java spring spring-mvc

我创建了spring mvc应用程序,并且我在D:\ propertiesfile.properties上有一个外部属性文件,我需要知道如何在servlet-context.xml中配置属性文件

 <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:property-placeholder location="file:D:\propertiesfile.properties>
<context:component-scan base-package="com.example.properties" />

但它不起作用。请指导我

1 个答案:

答案 0 :(得分:0)

如果可能,我建议使用弹簧靴。在spring boot中,你可以在编译的jar文件之外有一个application.properties,甚至没有定义它的位置,因为spring boot会自己找到它。它还带有自动配置,因此基本上“xml”和许多配置开销“死”。如果必要的话,你可以很容易地进行配置,我建议你看看这里:spring boot external configuration