Last active
October 2, 2015 18:58
-
-
Save HiroNakamura/2301328 to your computer and use it in GitHub Desktop.
Programando en Spring Framework 001
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
context.xml | |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" | |
"http://www.springframework.org/dtd/spring-beans.dtd"> | |
<beans> | |
<bean id="superman" class="org.springpruebas.prueba02.Superman"> | |
<property name="superPoder" ref="velocidad"/> | |
</bean> | |
<bean id="velocidad" class="org.springpruebas.prueba02.SuperVelocidad"/> | |
</beans> | |
SuperHeroe.java | |
package org.springpruebas.prueba02; | |
/** | |
* | |
* @author | |
*/ | |
public interface SuperHeroe { | |
public void hacerSuperCosas(); | |
} | |
Superman.java | |
package org.springpruebas.prueba02; | |
/** | |
* | |
* @author | |
*/ | |
public class Superman implements SuperHeroe { | |
private SuperPoder superPoder; | |
public void hacerSuperCosas() { | |
superPoder.usarPoder(); | |
} | |
/** | |
* @param superPoder the superPoder to set | |
*/ | |
public void setSuperPoder(SuperPoder superPoder) { | |
this.superPoder = superPoder; | |
} | |
} | |
SuperPoder.java | |
package org.springpruebas.prueba02; | |
/** | |
* | |
* @author | |
*/ | |
public interface SuperPoder { | |
public abstract void usarPoder(); | |
} | |
SuperVelocidad.java | |
package org.springpruebas.prueba02; | |
/** | |
* | |
* @author | |
*/ | |
public class SuperVelocidad implements SuperPoder { | |
public void usarPoder() { | |
System.out.println("Velocidad activada al 100% !!!"); | |
} | |
} | |
SuperMain.java | |
package org.springpruebas.prueba02; | |
import org.springframework.context.ApplicationContext; | |
import org.springframework.context.support.ClassPathXmlApplicationContext; | |
/** | |
* | |
* @author | |
*/ | |
public class SuperMain { | |
public static void main(String[] args) throws Exception { | |
ApplicationContext miApp= new ClassPathXmlApplicationContext("context.xml"); | |
SuperHeroe superman =(SuperHeroe) miApp.getBean("superman"); | |
superman.hacerSuperCosas(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment