Id Street Postcode: Public Class Private Int Private Private Public
Id Street Postcode: Public Class Private Int Private Private Public
Id Street Postcode: Public Class Private Int Private Private Public
public Address() {
@Override
public String toString() {
return "Address [" + " street=" + street + ", postCode="
+ postCode + "]";
}
}
@Configuration
public class ConfiguracionAplicacion {
@Bean("address")
Address direccion() {
Address address = new Address();
address.setId(1);
address.setStreet("cr 14 # 7b 69");
address.setPostCode("110011");
return address;
}
@Bean("person")
Person persona() {
Person person = new Person();
person.setId(1);
person.setName("alfonso");
Address direccion = new Address();
person.setAddress(direccion);
return person;
}
}
Clase donde ejecutamos la prueba. En el hacemos la inyección del bean de personas:
context = new
AnnotationConfigApplicationContext(ConfiguracionAplicacion.class);
System.out.println(person.toString());
}
}
Si queremos darle valores diferentes a los dados por defecto entonces se hace lo siguiente:
context = new
AnnotationConfigApplicationContext(ConfiguracionAplicacion.class);
System.out.println(person.toString());
}
}