🖨️ Version PDF
Objectif : comprendre ce que Spring fait pour vous et pourquoi on structure une application en couches. Petite introduction sur quelques concepts importants.
Sans framework, vous écrivez ceci :
public class PublicQueryController { private final ChienRepository chienRepository = new ChienRepositoryImpl(); // (exemple basique) }
PublicQueryController
Avec Spring : on déclare des dépendances et Spring les fournit.
Quand l’application démarre, Spring :
@RestController
@Service
@Repository
@Component
Règle d’or :
@RestController class MonController { private final MonService service; XController(MonService service) { this.service = service; } }
@RestController class MonController { @Autowired private MonService service; }
Pourquoi on préfère utiliser le constructeur ?
@SpringBootApplication
@SpringBootApplication public class WouafApplication { public static void main(String[] args) { SpringApplication.run(WouafApplication.class, args); } }
Cette annotation regroupe :
@Configuration
@EnableAutoConfiguration
@ComponentScan
Spring Boot détecte les dépendances :
Vous configurez le minimum utile, le reste est automatique.
UML sert à :
@Entity