Eclipse 从pom.xml设置活动spring概要文件并与IDE集成

Eclipse 从pom.xml设置活动spring概要文件并与IDE集成,eclipse,spring,maven,testing,configuration-files,Eclipse,Spring,Maven,Testing,Configuration Files,我致力于MavenizedJavaSpringWeb应用程序。我们在EclipseIDE中广泛使用自动重启和热部署,但我注意到,当您开始混合使用maven和spring配置时,Eclipse中的集成并不好。我们希望web.xml中有maven变量,在项目构建期间,这些变量将被maven war插件替换 web.xml中的Maven变量: <env-entry> <env-entry-name>spring.profiles.active</env-entry-

我致力于MavenizedJavaSpringWeb应用程序。我们在EclipseIDE中广泛使用自动重启和热部署,但我注意到,当您开始混合使用maven和spring配置时,Eclipse中的集成并不好。我们希望web.xml中有maven变量,在项目构建期间,这些变量将被maven war插件替换

web.xml中的Maven变量:

 <env-entry>
  <env-entry-name>spring.profiles.active</env-entry-name>
  <env-entry-type>java.lang.String</env-entry-type>
  <env-entry-value>${profileName}</env-entry-value>
 </env-entry>

spring.profiles.active
java.lang.String
${profileName}
在构建过程中,maven变量被maven war插件替换:

        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>    
            <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
            </configuration>
        </plugin>

maven战争插件
2.3
真的
此解决方案仅在我从命令行通过maven构建项目时有效。Eclipse热部署机制显然跳过了所有那些maven插件

您认为这是一个好的实践吗?是否有任何方法可以在eclipse中使用此配置无缝地工作


我可能会使用maven jetty插件在IDE之外运行它,但是我不喜欢在shell窗口中使用控制台—eclipse控制台—它更舒适。

通过maven build进行令牌筛选不适用于eclipse热部署

一个选项是将-Dspring.profiles.active=“dev”传递给JVM/App进程

我更喜欢使用env变量来控制配置文件加载。例如,MY_PROJECT_ENV=dev

以下代码读取变量并初始化配置文件

public class ProfileInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
    public void initialize(ConfigurableApplicationContext applicationContext) {
        ConfigurableEnvironment environment = applicationContext.getEnvironment();
        environment.setActiveProfiles(System.getProperty("MY_PROJECT_ENV"));
    }
}
公共类ProfileInitializer实现ApplicationContextInitializer{
public void初始化(ConfigurableApplicationContext applicationContext){
ConfigurableEnvironment=applicationContext.getEnvironment();
setActiveProfiles(System.getProperty(“MY_PROJECT_ENV”);
}
}