Skip to content

Instantly share code, notes, and snippets.

View jayanath's full-sized avatar

Jayanath Amaranayake jayanath

View GitHub Profile
@jayanath
jayanath / ServiceList.xml
Created July 30, 2012 20:04
Service List xml
<util:list id="services" value-type="com.jayanath.spring.services.Service">
<ref bean="InternetService"/>
<ref bean="TelephoneService"/>
</util:list>
<bean id="Room" name="Room" class="com.jayanath.spring.Room">
<constructor-arg name="roomType" value="Monte Carlo"/>
<property name="serviceList" ref="services"/>
</bean>
@jayanath
jayanath / appconfig.properties
Created July 30, 2012 19:59
appconfig property file
# Properties file to keep the frequently changing values
internet.service=Verizon FiOS Internet
telephone.service=Local long distance and international calls
laundry.service=Rapid dry cleaning
food.service=Breakfast and Dinner delivered to the room
@jayanath
jayanath / Internet_Bean_Impl.java
Created July 30, 2012 19:57
Internet Service Bean Impl
@Bean
public Internet internet() {
Internet i = new Internet();
i.setServiceName(env.getProperty("internet.service"));
return i;
}
@jayanath
jayanath / Internet_service.xml
Created July 30, 2012 19:56
Internet Service Bean
<bean id="InternetService" name="InternetService"
class="com.jayanath.spring.services.impl.Internet">
<property name="serviceName" value="${internet.service}"/>
</bean>
@jayanath
jayanath / configAnnotations.java
Created July 30, 2012 19:52
Config Annotations
@PropertySource("classpath:appconfig.properties")
@Autowired Environment env;
@jayanath
jayanath / propertyLoader.xml
Created July 30, 2012 19:48
property loader
<bean id="propertyLoader" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:appconfig.properties"/>
</bean>
public class Room {
//this annotation helps spring to identify the constructor
//argument names when we compile the classes without debug
//enabled
@ConstructorProperties({"roomType"})
public Room(String roomType) {
this.roomType = roomType;
}
public double calculateRoomCharge() {
@jayanath
jayanath / Internet.java
Created July 30, 2012 19:43
Internet Service
public class Internet implements Service {
private String serviceName;
@Override
public double calculateServiceCharge() {
return 10.19;
}
@Override
public String printServiceInfo() {
@jayanath
jayanath / Service.java
Created July 30, 2012 19:37
Service Interface
public interface Service {
double calculateServiceCharge();
String printServiceInfo();
}