Semana 03: API con Spring Boot
¿Qué es Spring?
* Framework
* Open Source
* Modular (*)
¿Qué nos ofrece?
* Inyección de Dependencias
* MVC
* Seguridad
* Acceso a datos, etc.
public Class Position {
private Double x;
private Double y;
public Position(Double x, Double y) {
this.x = x;
this.y = y;
}
@Override
public boolean hashCode() {
return Objects.hash(x, y);
}
}
@Component
public class PokemonService {
}
@Component
public class PokemonService {
private final PokemonRepository repository;
private final OtraDependencia otraDependencia;
@Autowired
public PokemonService(PokemonRepository repository, OtraDependencia otraDependencia) {
this.repository = repository;
this.otraDependencia = otraDependencia;
}
}
@Bean
Permite generar la construcción manual de ciertas instancias complejas.
@Configuration
Identificar la clase donde podremos agregar los Bean.
@Configuration
public class AppConfiguration {
@Bean
public Pokemon getPokemon() {
return new Pokemon("Pikachu");
}
}
Lab.02