• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

maven profile and spring property value

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


In above example, I want "dbHost" have different values per environment.  So in maven pom.xml, if I set



When I use Maven to build the EAR/WAR, I pass  "-P prod" (meaning use prod profile), will the <bean> in applicationContext.xml auto get the value of "www.prod.url"  ?
 
Saloon Keeper
Posts: 22265
151
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be hard-coding database connection information into a webapp. Webapps should use Database Connection Pools. They are much more efficient and much more flexible than brute-force database connections done in the app itself.

Connection pools are configured as part of the webserver, not the webapp, although you can generally define a pool specific to a single webapp and put its characteristics in as part of the server-specific deployment information. For example, a context.xml for Tomcat.

The webapp presents the Connection pool(s) defined for it via JNDI. In Spring, you can reference a pool like this:


Where I defined my pool as jdbc/localDB in my context.xml file when I deployed the webapp. You should then be able to use myDataSource.getConnection() to obtain a connection to work with.

Note that pool connections MUST NOT be held long-term. Use a pool connection for as little time as possible, then close it to return it to the pool so that it will be available to other webapp users. NEVER hold a connection between web requests (that's also true for non-pool connections, by the way).
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic