Showing posts with label spring. Show all posts
Showing posts with label spring. Show all posts

Monday, September 28, 2009

Loading a properties file using spring

Example properties file with filename:  fileOnHardDrive.properties

env.protocol=http
env.host=www.blogger.com

On your spring config file, you can load the properties file using the following code

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
        <list>
            <value>classpath:fileOnClasspath.properties</value>
            <value>file:fileOnHardDrive.properties</value>
        </list>
        </property>
</bean>

after that, you can now use the values on your properties file by using their key enclosed by a dollar sign and two curly braces. Example code:

<bean id="myUrl" class="java.net.URL">
        <constructor-arg value="${env.protocol}://${env.host}"/>
</bean>
Spring will now interpret the constructor arg value to be:
http://www.blogger.com
 
:) 

Wednesday, April 22, 2009

Spring and Hibernate

Personally, I don't like Spring (maybe because I didnt understand anything when the instructor taught it), but I LIKE hibernate (maybe because I got it on the first try because I just copy / pasted code) xD. SO ANYWAY I have to post code snippets here when I learn enough.

NOTE TO SELF: You have a blog.

(I hope I remember that note after a day or so haha ha.)

UPDATE [September 29, 2009]: Okay now I like Spring, I actually LOVE it. I don't like Hibernate anymore because after 5 months of not using it, I totally forgot how to use the thing. But hey! maybe I'll like it again after a while you never know! :D