{"id":1682,"date":"2012-08-14T22:00:00","date_gmt":"2012-08-14T22:00:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/spring-profiles-in-xml-config-files.html"},"modified":"2012-10-22T06:29:10","modified_gmt":"2012-10-22T06:29:10","slug":"spring-profiles-in-xml-config-files","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html","title":{"rendered":"Spring Profiles in XML Config Files"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">My last blog was very simple as it covered my painless upgrade from Spring 3.0.x to Spring 3.1.x and I finished by mentioning that you can upgrade your Spring schemas to 3.1 to allow you to take advantage of Spring\u2019s newest features. In today\u2019s blog, I&#8217;m going to cover one of the coolest of these features: Spring profiles. But, before talking about how you implement Spring profiles, I thought that it would be a good idea to explore the problem that they\u2019re solving, which is need to create different Spring configurations for different environments. This usually arises because your app needs to connect to several similar external resources during its development lifecycle and more often and not these \u2018external resources\u2019 are usually databases, although they could be JMS queues, web services, remote EJBs etc.<\/p>\n<p>The number of environments that your app has to work on before it goes lives usually depends upon a few of things, including your organizations business processes, the scale of the your app and it\u2019s &#8216;importance&#8217; (i.e. if you\u2019re writing the tax collection system for your country\u2019s revenue service then the testing process may be more rigorous than if you\u2019re writing an eCommerce app for a local shop). Just so that you get the picture, below is a quick (and probably incomplete) list of all the different environments that came to mind:                    <\/p>\n<ol>\n<li>Local Developer Machine<\/li>\n<li>Development Test Machine<\/li>\n<li>The Test Teams Functional Test Machine<\/li>\n<li>The Integration Test Machine<\/li>\n<li>Clone Environment (A copy of live)<\/li>\n<li>Live<\/li>\n<\/ol>\n<p>This is not a new problem and it\u2019s usually solved by creating a set of Spring XML and properties files for each environment. The XML files usually consist of a master file that imports other environment specific files. These are then coupled together at compile time to create different WAR or EAR files. This method has worked for years, but it does have a few problems:                     <\/p>\n<ol>\n<li>It\u2019s non-standard. Each organization usually has its own way of tackling this problem, with no two methods being quite the same\/<\/li>\n<li>It\u2019s difficult to implement leaving lots of room for errors.<\/li>\n<li>A different WAR\/EAR file has to be created for and deployed on each environment taking time and effort, which could be better spent writing code. <\/li>\n<\/ol>\n<p>The differences in the Spring beans configurations can normally be divided into two. Firstly, there are environment specific properties such as URLs and database names. These are usually injected into Spring XML files using the                     <tt>PropertyPlaceholderConfigurer<\/tt> class and the associated                     <tt>${}<\/tt> notation.<\/p>\n<pre class=\"brush:xml\">&lt;bean id='propertyConfigurer' class='org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'&gt;\r\n        &lt;property name='locations'&gt;\r\n            &lt;list&gt;\r\n                &lt;value&gt;db.properties&lt;\/value&gt;\r\n            &lt;\/list&gt;\r\n        &lt;\/property&gt;\r\n    &lt;\/bean&gt;<\/pre>\n<p>Secondly, there are environment specific bean classes such as data sources, which usually differ depending upon how you\u2019re connecting to a database.                    <\/p>\n<p>For example in development you may have:<\/p>\n<pre class=\"brush:xml\">&lt;bean id='dataSource' class='org.springframework.jdbc.datasource.DriverManagerDataSource'&gt;\r\n        &lt;property name='driverClassName'&gt;\r\n            &lt;value&gt;${database.driver}&lt;\/value&gt;\r\n        &lt;\/property&gt;\r\n        &lt;property name='url'&gt;\r\n            &lt;value&gt;${database.uri}&lt;\/value&gt;\r\n        &lt;\/property&gt;\r\n        &lt;property name='username'&gt;\r\n            &lt;value&gt;${database.user}&lt;\/value&gt;\r\n        &lt;\/property&gt;\r\n        &lt;property name='password'&gt;\r\n            &lt;value&gt;${database.password}&lt;\/value&gt;\r\n        &lt;\/property&gt;\r\n    &lt;\/bean&gt;<\/pre>\n<p>&#8230;whilst in test or live you&#8217;ll simply write:<\/p>\n<pre class=\"brush:xml\">&lt;jee:jndi-lookup id='dataSource' jndi-name='jdbc\/LiveDataSource'\/&gt;   <\/pre>\n<p>The Spring guidelines say that Spring profiles should only be used the second example above: bean specific classes and that you should continue to use                     <tt>PropertyPlaceholderConfigurer<\/tt> to initialize simple bean properties; however, you may want to use Spring profiles to inject an environment specific                     <tt>PropertyPlaceholderConfigurer<\/tt> in to your Spring context.                     <div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Having said that, I\u2019m going to break this convention in my sample code as I want the simplest code possible to demonstrate Spring profile\u2019s features.                     <\/p>\n<p><strong>Spring Profiles and XML Configuration<\/strong><br \/>\nIn terms of XML configuration, Spring 3.1 introduces the new                     <tt>profile<\/tt> attribute to the                     <tt>beans<\/tt> element of the spring-beans schema:<\/p>\n<pre class=\"brush:xml\">&lt;beans profile='dev'&gt;<\/pre>\n<p>It\u2019s this                     <tt>profile<\/tt> attribute that acts as a switch when enabling and disabling profiles in different environments.                     <\/p>\n<p>To explain all this further I\u2019m going to use the simple idea that your application needs to load a person class, and that person class contains different properties depending upon the environment on which your program is running.                    <\/p>\n<p>The                     <tt>Person<\/tt> class is very trivial and looks something like this:<\/p>\n<pre class=\"brush:java\">public class Person {\r\n\r\n\r\n\r\n  private final String firstName;\r\n\r\n  private final String lastName;\r\n\r\n  private final int age;\r\n\r\n\r\n\r\n  public Person(String firstName, String lastName, int age) {\r\n\r\n    this.firstName = firstName;\r\n\r\n    this.lastName = lastName;\r\n\r\n    this.age = age;\r\n\r\n  }\r\n\r\n\r\n\r\n  public String getFirstName() {\r\n\r\n    return firstName;\r\n\r\n  }\r\n\r\n\r\n\r\n  public String getLastName() {\r\n\r\n    return lastName;\r\n\r\n  }\r\n\r\n\r\n\r\n  public int getAge() {\r\n\r\n    return age;\r\n\r\n  }\r\n\r\n}<\/pre>\n<p>&#8230;and is defined in the following XML configuration files:<\/p>\n<pre class=\"brush:xml\">&lt;?xml version='1.0' encoding='UTF-8'?&gt;\r\n&lt;beans xmlns='http:\/\/www.springframework.org\/schema\/beans'\r\n xmlns:xsi='http:\/\/www.w3.org\/2001\/XMLSchema-instance'\r\n xsi:schemaLocation='http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.1.xsd'\r\n  profile='test1'&gt;\r\n\r\n &lt;bean id='employee' class='profiles.Person'&gt;\r\n  &lt;constructor-arg value='John' \/&gt;\r\n  &lt;constructor-arg value='Smith' \/&gt;\r\n  &lt;constructor-arg value='89' \/&gt;\r\n &lt;\/bean&gt;\r\n&lt;\/beans&gt;<\/pre>\n<p>&#8230;and<\/p>\n<pre class=\"brush:xml\">&lt;?xml version='1.0' encoding='UTF-8'?&gt;\r\n&lt;beans xmlns='http:\/\/www.springframework.org\/schema\/beans'\r\n xmlns:xsi='http:\/\/www.w3.org\/2001\/XMLSchema-instance'\r\n xsi:schemaLocation='http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.1.xsd'\r\n  profile='test2'&gt;\r\n\r\n &lt;bean id='employee' class='profiles.Person'&gt;\r\n  &lt;constructor-arg value='Fred' \/&gt;\r\n  &lt;constructor-arg value='ButterWorth' \/&gt;\r\n  &lt;constructor-arg value='23' \/&gt;\r\n &lt;\/bean&gt;\r\n&lt;\/beans&gt;<\/pre>\n<p>&#8230;called                     <tt>test-1-profile.xml<\/tt> and                     <tt>test-2-profile.xml<\/tt> respectively (remember these names, they&#8217;re important later on). As you can see, the only differences in configuration are the first name, last name and age properties.                    <\/p>\n<p>Unfortunately, it\u2019s not enough simply to define your profiles, you have to tell Spring which profile you\u2019re loading. This means that following old \u2018standard\u2019 code will now fail:<\/p>\n<pre class=\"brush:java\">  @Test(expected = NoSuchBeanDefinitionException.class)\r\n\r\n  public void testProfileNotActive() {\r\n\r\n\r\n\r\n    \/\/ Ensure that properties from other tests aren't set\r\n\r\n    System.setProperty('spring.profiles.active', '');\r\n\r\n\r\n\r\n    ApplicationContext ctx = new ClassPathXmlApplicationContext('test-1-profile.xml');\r\n\r\n\r\n\r\n    Person person = ctx.getBean(Person.class);\r\n\r\n    String firstName = person.getFirstName();\r\n\r\n    System.out.println(firstName);\r\n\r\n  }<\/pre>\n<p>Fortunately there are several ways of selecting your profile and to my mind the most useful is by using the &#8216;spring.profiles.active&#8217; system property. For example, the following test will now pass:<\/p>\n<pre class=\"brush:java\">    System.setProperty('spring.profiles.active', 'test1');\r\n\r\n    ApplicationContext ctx = new ClassPathXmlApplicationContext('test-1-profile.xml');\r\n\r\n\r\n\r\n    Person person = ctx.getBean(Person.class);\r\n\r\n    String firstName = person.getFirstName();\r\n\r\n    assertEquals('John', firstName);<\/pre>\n<p>Obviously, you wouldn\u2019t want to hard code things as I\u2019ve done above and best practice usually means keeping the system properties definitions separate to your application. This gives you the option of using either a simple command line argument such as:<\/p>\n<pre class=\"brush:java\">-Dspring.profiles.active='test1'<\/pre>\n<p>&#8230;or by adding<\/p>\n<pre class=\"brush:java\"># Setting a property value\r\nspring.profiles.active=test1<\/pre>\n<p>to Tomcat\u2019s                     <tt>catalina.properties<\/tt>                   <\/p>\n<p>So, that\u2019s all there is to it: you create your Spring XML profiles using the                     <tt>beans<\/tt> element                     <tt>profile<\/tt> attribute and switch on the profile you want to use by setting the                     <tt>spring.profiles.active<\/tt> system property to your                     <tt>profile<\/tt>\u2019s name.                    <\/p>\n<p><strong>Accessing Some Extra Flexibility<\/strong>                   <\/p>\n<p>However, that\u2019s not the end of the story as the Guy\u2019s at Spring has added a number of ways of programmatically loading and enabling profiles &#8211; should you choose to do so.<\/p>\n<pre class=\"brush:java\">  @Test\r\n\r\n  public void testProfileActive() {\r\n\r\n\r\n\r\n    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(\r\n\r\n        'test-1-profile.xml');\r\n\r\n    ConfigurableEnvironment env = ctx.getEnvironment();\r\n\r\n    env.setActiveProfiles('test1');\r\n\r\n    ctx.refresh();\r\n\r\n\r\n\r\n    Person person = ctx.getBean('employee', Person.class);\r\n\r\n    String firstName = person.getFirstName();\r\n\r\n    assertEquals('John', firstName);\r\n\r\n  }<\/pre>\n<p>In the code above, I\u2019ve used the new                     <tt>ConfigurableEnvironment<\/tt> class to activate the \u201ctest1\u201d profile.<\/p>\n<pre class=\"brush:java\">  @Test\r\n\r\n  public void testProfileActiveUsingGenericXmlApplicationContextMultipleFilesSelectTest1() {\r\n\r\n\r\n\r\n    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();\r\n\r\n    ConfigurableEnvironment env = ctx.getEnvironment();\r\n\r\n    env.setActiveProfiles('test1');\r\n\r\n    ctx.load('*-profile.xml');\r\n\r\n    ctx.refresh();\r\n\r\n\r\n\r\n    Person person = ctx.getBean('employee', Person.class);\r\n\r\n    String firstName = person.getFirstName();\r\n\r\n    assertEquals('John', firstName);\r\n\r\n  }<\/pre>\n<p>However, The Guys At Spring now recommend that you use the                     <tt>GenericApplicationContext<\/tt> class instead of                     <tt>ClassPathXmlApplicationContext<\/tt> and                     <tt>FileSystemXmlApplicationContext<\/tt> as this provides additional flexibility. For example, in the code above, I\u2019ve used                     <tt>GenericApplicationContext<\/tt>\u2019s                     <tt>load(...)<\/tt> method to load a number of configuration files using a wild card:<\/p>\n<pre class=\"brush:java\">    ctx.load('*-profile.xml');<\/pre>\n<p>Remember the filenames from earlier on? This will load both                     <tt>test-1-profile.xml<\/tt> and                     <tt>test-2-profile.xml<\/tt>.                    <\/p>\n<p>Profiles also include additional flexibility that allows you to activate more than one at a time. If you take a look at the code below, you can see that I\u2019m activating both of my                     <tt>test1<\/tt> and                     <tt>test2<\/tt> profiles:<\/p>\n<pre class=\"brush:java\">  @Test\r\n\r\n  public void testMultipleProfilesActive() {\r\n\r\n\r\n\r\n    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();\r\n\r\n    ConfigurableEnvironment env = ctx.getEnvironment();\r\n\r\n    env.setActiveProfiles('test1', 'test2');\r\n\r\n    ctx.load('*-profile.xml');\r\n\r\n    ctx.refresh();\r\n\r\n\r\n\r\n    Person person = ctx.getBean('employee', Person.class);\r\n\r\n    String firstName = person.getFirstName();\r\n\r\n    assertEquals('Fred', firstName);\r\n\r\n  }<\/pre>\n<p>Beware, in the case of this example I have two beans with the same id of \u201cemployee\u201d, and there\u2019s no way of telling which one is valid and is supposed to take precedence. From my test, I guessing that the second one that\u2019s read overwrites, or masks access to, the first. This is okay as you\u2019re not supposed to have multiple beans with the same name &#8211; it\u2019s just something to watch out for when activating multiple profiles.                    <\/p>\n<p>Finally, one of the better simplifications you can make is to use nested &lt;beans\/&gt; elements.<\/p>\n<pre class=\"brush:xml\">&lt;?xml version='1.0' encoding='UTF-8'?&gt;\r\n&lt;beans xmlns='http:\/\/www.springframework.org\/schema\/beans'\r\n xmlns:xsi='http:\/\/www.w3.org\/2001\/XMLSchema-instance' xmlns:context='http:\/\/www.springframework.org\/schema\/context'\r\n xsi:schemaLocation='http:\/\/www.springframework.org\/schema\/beans http:\/\/www.springframework.org\/schema\/beans\/spring-beans-3.1.xsd\r\n  http:\/\/www.springframework.org\/schema\/context http:\/\/www.springframework.org\/schema\/context\/spring-context-3.1.xsd'&gt;\r\n\r\n &lt;beans profile='test1'&gt;\r\n  &lt;bean id='employee1' class='profiles.Person'&gt;\r\n   &lt;constructor-arg value='John' \/&gt;\r\n   &lt;constructor-arg value='Smith' \/&gt;\r\n   &lt;constructor-arg value='89' \/&gt;\r\n  &lt;\/bean&gt;\r\n &lt;\/beans&gt;\r\n\r\n &lt;beans profile='test2'&gt;\r\n  &lt;bean id='employee2' class='profiles.Person'&gt;\r\n   &lt;constructor-arg value='Bert' \/&gt;\r\n   &lt;constructor-arg value='William' \/&gt;\r\n   &lt;constructor-arg value='32' \/&gt;\r\n  &lt;\/bean&gt;\r\n &lt;\/beans&gt;\r\n\r\n&lt;\/beans&gt;<\/pre>\n<p>This takes away all the tedious mucking about with wild cards and loading multiple files, albeit at the expense of a minimal amount of flexibility.                    <\/p>\n<p>My next blog concludes my look at Spring profiles, by taking a look at the                     <tt>@Configuration<\/tt> annotation used in conjunction with the new                     <tt>@Profile<\/tt> annotation&#8230; so, more on that later.                    <\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/www.captaindebug.com\/2012\/08\/using-spring-profiles-in-xml-config.html\">Using Spring Profiles in XML Config<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Roger Hughes at the <a href=\"http:\/\/www.captaindebug.com\/\">Captain Debug&#8217;s Blog <\/a> blog.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>My last blog was very simple as it covered my painless upgrade from Spring 3.0.x to Spring 3.1.x and I finished by mentioning that you can upgrade your Spring schemas to 3.1 to allow you to take advantage of Spring\u2019s newest features. In today\u2019s blog, I&#8217;m going to cover one of the coolest of these &hellip;<\/p>\n","protected":false},"author":65,"featured_media":240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[30,107],"class_list":["post-1682","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-spring","tag-xml"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spring Profiles in XML Config Files - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"My last blog was very simple as it covered my painless upgrade from Spring 3.0.x to Spring 3.1.x and I finished by mentioning that you can upgrade your\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring Profiles in XML Config Files - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"My last blog was very simple as it covered my painless upgrade from Spring 3.0.x to Spring 3.1.x and I finished by mentioning that you can upgrade your\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2012-08-14T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-22T06:29:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Roger Hughes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Roger Hughes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html\"},\"author\":{\"name\":\"Roger Hughes\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c9feacaf8e783104a69621cd65bf1f07\"},\"headline\":\"Spring Profiles in XML Config Files\",\"datePublished\":\"2012-08-14T22:00:00+00:00\",\"dateModified\":\"2012-10-22T06:29:10+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html\"},\"wordCount\":1170,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"keywords\":[\"Spring\",\"XML\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html\",\"name\":\"Spring Profiles in XML Config Files - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"datePublished\":\"2012-08-14T22:00:00+00:00\",\"dateModified\":\"2012-10-22T06:29:10+00:00\",\"description\":\"My last blog was very simple as it covered my painless upgrade from Spring 3.0.x to Spring 3.1.x and I finished by mentioning that you can upgrade your\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/spring-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"spring-interview-questions-answers\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/08\\\/spring-profiles-in-xml-config-files.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Spring Profiles in XML Config Files\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c9feacaf8e783104a69621cd65bf1f07\",\"name\":\"Roger Hughes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g\",\"caption\":\"Roger Hughes\"},\"sameAs\":[\"http:\\\/\\\/www.captaindebug.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Roger-Hughes\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring Profiles in XML Config Files - Java Code Geeks","description":"My last blog was very simple as it covered my painless upgrade from Spring 3.0.x to Spring 3.1.x and I finished by mentioning that you can upgrade your","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html","og_locale":"en_US","og_type":"article","og_title":"Spring Profiles in XML Config Files - Java Code Geeks","og_description":"My last blog was very simple as it covered my painless upgrade from Spring 3.0.x to Spring 3.1.x and I finished by mentioning that you can upgrade your","og_url":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2012-08-14T22:00:00+00:00","article_modified_time":"2012-10-22T06:29:10+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Roger Hughes","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Roger Hughes","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html"},"author":{"name":"Roger Hughes","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c9feacaf8e783104a69621cd65bf1f07"},"headline":"Spring Profiles in XML Config Files","datePublished":"2012-08-14T22:00:00+00:00","dateModified":"2012-10-22T06:29:10+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html"},"wordCount":1170,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","keywords":["Spring","XML"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html","url":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html","name":"Spring Profiles in XML Config Files - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","datePublished":"2012-08-14T22:00:00+00:00","dateModified":"2012-10-22T06:29:10+00:00","description":"My last blog was very simple as it covered my painless upgrade from Spring 3.0.x to Spring 3.1.x and I finished by mentioning that you can upgrade your","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/spring-logo.jpg","width":150,"height":150,"caption":"spring-interview-questions-answers"},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2012\/08\/spring-profiles-in-xml-config-files.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Spring Profiles in XML Config Files"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c9feacaf8e783104a69621cd65bf1f07","name":"Roger Hughes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g","caption":"Roger Hughes"},"sameAs":["http:\/\/www.captaindebug.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Roger-Hughes"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/1682","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=1682"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/1682\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/240"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=1682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=1682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=1682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}