2

我根据 spring 活动配置文件限制了 bean 的创建。因此,这些在生产环境中无法访问

<beans profile="test">  
    <bean id="testSwaggerConfig" class="com.example.rest.config.SwaggerConfig" />
</beans>

同样,如何根据 spring active profiles 限制资源。因此,在访问 html 页面时,我应该得到404

<mvc:resources mapping="/rest/*.html" location="/rest-doc/" />

我正在从环境变量传递活动配置文件-Dspring.profiles.active(可能此信息对某人有用)

4

1 回答 1

0

您可以像这样为每个配置文件定义参数bean

<bean name="profileParam" class="java.lang.String">
    <constructor-arg value="/rest/*.html" />
</bean>

并在参数中放置所需的映射然后像这样使用配置文件中的参数

<mvc:resources mapping="#{profileParam}" location="/rest-doc/" />

因此,对于不同的配置文件,您可以访问不同的映射

于 2015-03-06T08:53:28.800 回答