This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Service { | |
double calculateServiceCharge(); | |
String printServiceInfo(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Internet implements Service { | |
private String serviceName; | |
@Override | |
public double calculateServiceCharge() { | |
return 10.19; | |
} | |
@Override | |
public String printServiceInfo() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean id="propertyLoader" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> | |
<property name="locations" value="classpath:appconfig.properties"/> | |
</bean> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@PropertySource("classpath:appconfig.properties") | |
@Autowired Environment env; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<bean id="InternetService" name="InternetService" | |
class="com.jayanath.spring.services.impl.Internet"> | |
<property name="serviceName" value="${internet.service}"/> | |
</bean> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public Internet internet() { | |
Internet i = new Internet(); | |
i.setServiceName(env.getProperty("internet.service")); | |
return i; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Bean | |
public Room room() { | |
Room r = new Room("Monte Carlo"); | |
List<Service> list = new ArrayList<Service>(); | |
list.add(internet()); | |
list.add(telephone()); | |
r.setServiceList(list); | |
return r; | |
} |
OlderNewer