在 GWT 托管模式下激活 Spring Profile 活动 JVM 参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9118909/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 04:54:38  来源:igfitidea点击:

Activating Spring Profile active JVM arguments in GWT hosted mode

springgwtmavenmaven-3

提问by Aravind A

I have a spring profile configuration as shown below

我有一个弹簧配置文件,如下所示

<beans profile="dev">
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="${db.driverClassName}" />
        <property name="jdbcUrl" value="dfgdfg" />
        <property name="user" value="${db.username}" />
        <property name="password" value="${db.password}" />
    </bean>
</beans>

<beans profile="prod">
    <jee:jndi-lookup id="dataSource" jndi-name="jdbc/Test"/>
</beans>

I am trying to make one of this active via the VM argument -Dspring.profiles.active="dev". This works in Tomcat and so does the context-paramroute in Hosted mode via the gwt-maven-plugin but I can't get the VM arguments to work . I tried mvn -Dspring.profiles.active="dev" gwt:runalso tried to pass -Dspring.profiles.active="dev"via the VM arguments under the JRE tab in run configurations along with the goal gwt:run. I also tried the environment tab and even -Dspring.profiles.active=devbut the NoSuchBeanDefinitionExceptiondoesn't budge . Is this because of the limited capability of the embedded server ?

我试图通过 VM 参数激活其中之一-Dspring.profiles.active="dev"。这在 Tomcat 中有效,context-param通过 gwt-maven-plugin 在托管模式下的路由也是如此,但我无法让 VM 参数工作。我mvn -Dspring.profiles.active="dev" gwt:run还尝试-Dspring.profiles.active="dev"通过运行配置中 JRE 选项卡下的 VM 参数以及目标传递gwt:run。我也尝试了环境选项卡,甚至-Dspring.profiles.active=devNoSuchBeanDefinitionException没有让步。这是因为嵌入式服务器的能力有限吗?

回答by jusio

No, simply gwt:maven plugin is kind of strange and it doesn't pass system properties to the launched JVM instance, and the only way to pass parameters is to put it into <extraJvmArgs>in plugin configuration e.g. in your case you have to add following to the configuration tag of gwt plugin:

不,只是 gwt:maven 插件有点奇怪,它不会将系统属性传递给启动的 JVM 实例,传递参数的唯一方法是将其放入<extraJvmArgs>插件配置中,例如在您的情况下,您必须添加以下内容gwt插件的配置标签:

<extraJvmArgs>-Dspring.profiles.active=dev</extraJvmArgs>

<extraJvmArgs>-Dspring.profiles.active=dev</extraJvmArgs>

God knows why this works only this way, I wish there were some other normal way.

天知道为什么这只能以这种方式工作,我希望有其他一些正常的方式。