Posts

Showing posts from May, 2013

Spring : Encrypt Spring Datasource Password Credentials

Encrypt Spring Datasource Password Credentials (1)  EncryptedDataSource.java I have written a wrapper class EncryptedDataSource for org.springframework.jdbc. datasource. DriverManagerDataSource and overridden getPassword() method. EncryptedDataSource class is injected in spring datasource configuration xml file. Which calls the overriden getPassword() method of data-source at the time of database connection. getPassword() method decode the encrypted password into actual password. To decrypt or encrypt password we used "BASE64Decoder" algorithm.   import  java.io.IOException;   import  org.springframework.jdbc. datasource. DriverManagerDataSource;   import  sun.misc.BASE64Decoder;   import  sun.misc.BASE64Encoder;   public   class  EncryptedDataSource  extends  DriverManagerDataSource{                     @Override            public...

Spring : Reading Properties file

Spring 2.5 : Reading Properties file: PropertyPlaceholderConfigurer : The PropertyPlaceholderConfigurer is used to externalize property values from a BeanFactory definition, into another separate file in the standard Java Properties format. This is useful to allow the person deploying an application to customize environment-specific properties (for example database URLs, usernames and passwords), without the complexity or risk of modifying the main XML definition file or files for the container.   <bean   class = "org.springframework. beans.factory.config. PropertyPlaceholderConfigurer" >        <property   name = "location" >                <value>database.properties</ value>        </property> </bean>   Getting Property Value in Spring Configuration: Use ${propertyKey}   <bean id="dataSource"  class="org.springframework. jdbc.data...

Struts2 Spring Integration and Accessing ApplicationContext

Struts2 Spring Integration   To enable Spring integration, simply include struts2-spring-plugin-x-x-x. jar in your application.   If you are using more than one object factory, (for example, by including both the Spring and Plexus plugins in your application,) you will need to set the struts.objectFactory property in  struts.properties  or in one of several XML files via  Constant Configuration : struts.properties struts.objectFactory = spring struts.xml <struts>  <constant name="struts.objectFactory" value="spring" />  ... </struts> Configure the Spring listener  - web.xml <listener>    <listener-class>org. springframework.web.context. ContextLoaderListener</ listener-class> </listener> More applicationContext configuration files needed? Since the Spring integration uses a standard Listener, it can be configured to support configuration files other than applicationContext.xml. Add...