Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

java - Default profile in Spring 3.1

In my application I have beans annotated with @Profile("prod") and @Profile("demo"). The first one, as you can guess :), is used on beans that connect to production DB and second one annotates beans that use some fake DB (HashMap or whatever)- to make development faster.

What I would like to have is default profile ("prod") that will be used always if it is not overridden by "something-else".

Perfect would be to have in my web.xml:

<context-param>
     <param-name>spring.profiles.active</param-name>
     <param-value>prod</param-value>
</context-param>

and then override this with -Dspring.profiles.active="demo" so that I could do:

mvn jetty:run -Dspring.profiles.active="demo". 

But sadly this is not working. Any idea how could I achive that? Setting -Dspring.profiles.active="prod" on all my environments is not an option.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Define your production environment as default profile in your web.xml

<context-param>
   <param-name>spring.profiles.default</param-name>
   <param-value>prod</param-value>
</context-param>

and if you want to use a different profile pass it as system property

mvn -Dspring.profiles.active="demo" jetty:run

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...