tag:blogger.com,1999:blog-3237724005744642470.post8424223095601337805..comments2018-05-25T20:51:48.285+01:00Comments on Captain Debug's Blog: Using Spring Profiles and Java ConfigurationRoger Hugheshttp://www.blogger.com/profile/07042290171112551665[email protected]Blogger4125tag:blogger.com,1999:blog-3237724005744642470.post-20075981774749619352013-01-04T08:38:41.580+00:002013-01-04T08:38:41.580+00:00You can only declare a profile using web.xml if yo...You can only declare a profile using web.xml if you're using a web server. In the sample you've given, you're trying to load web.xml from a main() method. If you want to use main() then the first thing to try would be to specify your profile using a -D arg as described above. You'll also need to load your Spring config file.<br />Roger Hugheshttps://www.blogger.com/profile/07042290171112551665[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-51547656042130750652013-01-03T22:38:17.659+00:002013-01-03T22:38:17.659+00:00Thanks Roger for your reply.
I have declared one...Thanks Roger for your reply. <br />I have declared one profile in web.xml like<br /><br />context-param<br /> param name<br />spring.profiles.active /param-name<br />param-value dev /param-value<br />/context-param<br /><br />Can you tell me how can i get value of active profile in Java class?<br /><br />Here is piece of code.<br />public static void main(String args[]){<br /> GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();<br /> ctx.getEnvironment().getActiveProfiles();<br /> <br />But it doesn't work due to some reasonsAnonymous[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-14654924337761970852012-12-29T16:24:54.135+00:002012-12-29T16:24:54.135+00:00Not quite sure what you mean in your first questio...Not quite sure what you mean in your first question. If you read my blog again you'll see that Spring don't recommend using profiles simply for setting bean properties using PropertyPlaceholderConfigurer , they're really for creating different Spring context configurations (i.e. groups of beans held in an application context) for different environments.<br /><br /><br />You only need to add the profile=test etc. into you Java configuration classes, that is the ones you annotate with @Configuration. These classes can be used to create the objects that you require as part of your Spring context. The idea here is that you would write a different configuration class for each profile - eg one for test, one for dev, one for production etc. These would then create different versions of your Spring context objects, which are all neatly referenced using interfaces.<br />Roger Hugheshttps://www.blogger.com/profile/07042290171112551665[email protected]tag:blogger.com,1999:blog-3237724005744642470.post-78871822820508240502012-12-22T01:45:54.430+00:002012-12-22T01:45:54.430+00:00Hi Roger
Thanks for sharing this article. This is...Hi Roger<br /><br />Thanks for sharing this article. This is what i am looking for. Actually, I am working on Spring 3 and implementing same thing in my project using spring 3. I am wondering if you have source code that covers different profiles like dev, testing which reads the properties database properties files or log file using spring 3.<br /><br />I have couple of questions:<br /><br />1) How can we create session factory in Spring 3 using PropertyPlaceholderConfigurer?<br /><br />3) For Spring Profiling, is there any way available to set profiles.active="test1" only once in application rather including (profile="test") annotation in every class? i know you have covered few things in this article but i am bit confused. <br /><br />If you have source code for these things what i have mentioned in this post, then can you please upload here.<br /><br />Thanks,<br />Zaghman Arshad<br />zaghman Arshadhttps://www.blogger.com/profile/03232489167302265975[email protected]