我在Spring 3.2.4上有Spring MVC Web應用程序。 我有2個上下文。 1. MVC-調度-servlet.xml中看起來像這樣:如何共享2場景的propertyplaceholder
<context:annotation-config/>
<context:component-scan base-package="com.ja.dom"/>
<!-- Tiles 3 config -->
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<!--Don't add suffix or prefix like you do with .jsp files-->
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer" >
<property name="definitions">
<value>/WEB-INF/tiles.xml</value>
</property>
</bean>
和2根context.xml中是這樣的:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:prop.properties"/>
</bean>
<!-- Mail Sender Bean -->
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="smtp.gmail.com" />
<property name="port" value="587" />
<property name="username" value="${email.name}" />
<property name="password" value="${email.password}" />
<property name="defaultEncoding" value="UTF-8"/>
<property name="javaMailProperties">
<props>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.smtp.starttls.enable">true</prop>
<prop key="mail.debug">true</prop>
</props>
</property>
</bean>
當運行應用程序時,我看看只有mailSender bean具有來自屬性文件的參數。 我的其他豆類等@Service ..不被注入。怎麼了? 如何將我的PropertyPlaceholderConfigurer共享到mvc-dispatcher-servlet上下文?
我注入性質的服務是這樣的:
@Value( 「$ {} reCaptcha.private.key」) 私人字符串reCaptchaPrivateKey;
和我的web.xml (UPDATE)
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Spring MVC Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!--<init-param>-->
<!--<param-name>contextConfigLocation</param-name>-->
<!--<param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>-->
<!--</init-param>-->
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
2屬性每個上下文文件的佔位符bean?對? – Benjamin
@jToM每一個,是的。 –
這是最好的春季做法? – Benjamin