Spring loading property files & properties

conf/db.properties

# jdbc.X
jdbc.driverClassName=org.hsqldb.jdbcDriver
jdbc.url=jdbc:hsqldb:hsql://localhost/mytestdb
jdbc.user=SA
jdbc.pass=
# hibernate.X
hibernate.dialect=org.hibernate.dialect.HSQLDialect
hibernate.show_sql=false
hibernate.hbm2ddl.auto=

#1. Register a Properties File in Application Context XML

The “<property-placeholder>” tag.

OR

#2. Register a Properties File via Java configuration

The @PropertySource annotation.

OR

#3. Injecting the properties via annotations

#4. Accessing via the Environment API

#5. Using the custom ApplicationContextInitializer or WebApplicationInitializer

Spring 3.1 introduced a very convenient hook for customizing the application context with ApplicationContextInitializer. It can be used to set active profiles and register custom property sources. Spring loading properties files with ApplicationContextInitializer or with WebApplicationInitializer.

The “WebApplicationInitializer” is applicable in a Servlet 3.0+ compliant servlet container and provides a hook to pro-grammatically configure the servlet context.


Java Interview FAQs

800+ Java Interview Q&As

Top