• Saltar a la navegación principal
  • Skip to main content
  • Saltar a la barra lateral principal

Geekebrains

Para programadores, maker y geeks en general

  • Inicio
  • YouTube
  • Zona makers!
  • Zona Coders!
  • Zona Junior!
Estás aquí: Inicio / Zona Coders! / Spring Framework de Java

2 febrero, 2020 Por admin8049 Deja un comentario

Spring Framework de Java

Anotaciones

Spring MVC – Controller

@ControllerAnnotation to indicate that the class is a controller class.
@RestControllerA conven­ience annotation that is itself annotated with @Cont­roller and @Resp­ons­eBody. Used in contro­llers that will behave as RESTful resour­ces.
@RequestMappingAnnotation to be used on methods in @Rest­Con­tro­ller classes. You can provide an URI to be served as RESTful service.
@ModelAttributeAnnotation used to bind values present in views.

Config­uration

@ConfigurationAnnotation used to provide conf­igu­rat­ions.
@BeanAnnotation that acts like a prov­ider where you can define how the bean is inst­ant­iated when a inje­ction of that type is requested. Instances of @Bean annotated methods will act as sing­let­ons.

Properties Evaluation Sequence

Command-line argumentsjava -Dproj­ect.na­me=Test -jar app.jar
System propertiesSyste­m.g­etP­rop­ert­ies()
Enviro­nment Variableexport PROJEC­T_N­AME­=Test
External proper­tie­s/yml fileproje­ct.n­am­e=Test
Internal proper­tie­s/yml fileproje­ct.n­am­e=Test

The default proper­tie­s/yml files are appl­ica­tio­n.p­rop­ert­ies and appl­ica­tio­n.yml and they are located in /src/­res­our­ces.

Spring Boot Initia­lizer

http://start.spring.ioWeb service that allows the user to specify the project metadata and depend­encies as well as download the initial structure.
Spring CLIA CLI tool that interacts with http­://­sta­rt.s­pr­ing.io service to scaffold a new project.
Spring Tool SuitEclips­e-based IDE that also interacts with http­://­sta­rt.s­pr­ing.io to scaffold a new project.
Intellij IDEAIntellij also provides a way of creating a new project via http­://­sta­rt.s­pr­ing.io.

Spring Boot – Auto Config­uration

@ConditionalOnClass@Cond­iti­ona­lOn­Cla­ss(­Tom­cat.cl­ass)Only available if the Tomcat class is found in the classpath.
@ConditionalOnProperty@Cond­iti­ona­lOn­Pro­per­ty(name = "­tom­cat.ve­rsi­on", matchI­fMi­ssing = true)Only available if the property tomca­t.v­ersion is set to true.

Auto config­uration is just the combin­ation of @Conf­igu­ration and @Cond­iti­onal* annota­tions in order to correctly register beans.

Dependency Injection

@ResourceAnnotation used to inject an object that is already in the Appl­ication Context. It searches the instance by name. It also works on setter methods.
@AutowiredAnnotation used to inject objects in many possible ways, such as: instance variable, constr­uctor and methods. It does not rely on name as @Reso­urce, so, for multiple concrete implem­ent­ations, the @Qual­ifier annotation must be used with it.
@QualifierAnnotation used to dist­ing­uish between mult­iple concrete implem­ent­ations. Used alongside with @Auto­wired annotation that does not rely on name.
@PrimaryAnnotation used when no name is provided telling Spring to inject an object of the annotated class first. Used along with @Comp­onent.
@ComponentGeneric stereotype annotation used to tell Spring to create an instance of the object in the Appl­ication Context. It’s possible to define any name for the instance, the default is the class name as camel case.
@Contr­ollerStereotype annotation for presen­tation layer.
@Repos­itoryStereotype annotation for persis­tence layer.
@ServiceStereotype annotation for service layer.

Profile

spring.profiles.activeProperty to be set in appl­ica­tio­n.p­rop­ert­ies in order to tell Spring what profiles are active.
@Profile(«!dev»)Annotation used to define which profile can execute the annotated method.

Spring Boot – Basics

@SpringBootApplicationInitial annotation that comprises the following annota­tions: @Spri­ngB­oot­Con­fig­ura­tion, @Enab­leA­uto­Con­fig­ura­tion and @Comp­one­ntS­can.
@Spri­­ngB­­oo­t­C­on­­fig­­ur­a­tionIndicates that a class provides Spring Boot applic­ation @Conf­igu­rat­ion.
@Enab­­leA­­ut­o­C­on­­fig­­ur­a­tionEnable auto-c­onf­igu­ration of the Spring Applic­ation Context, attempting to guess and configure beans that you are likely to need.
@Comp­­one­­nt­S­canConfigures component scanning directives for use with @Conf­igu­ration classes.

Most of the time you will need only to declare the @Spri­ngB­oot­App­lic­ation annota­tion.

Spring Boot – Example

Archivado en: Conceptos, Zona Coders! Etiquetado como: Java, MVC, Spring Framework

Entrada anterior: « Expresiones regulares
Siguiente entrada: Proyecto de Control remoto RC con arduino y nRF24L01 »

Interacciones del lector

Deja una respuesta Cancelar la respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

Barra lateral primaria

Categorías

  • Conceptos
  • Experimentos
  • GeekeBlocks
  • Noticias Geek
  • Proyectos
  • Sin categoría
  • Zona Coders!
  • Zona Junior!
  • Zona makers!

Etiquetas

Arduino Arduino nano Atom backup Buenas prácticas docker docker-compose dockerfile ECMAScript6 (2015) EditorConfig ES6 ESLint Expresiones regulares git IDE Java javascript JSON JSX lenguajes de programación Librerías de JavaScript mac Material UI MongoDb MVC NetBeans node NodeJS NoSQL Notepad++ nRF24L01 nvm odoo package.json plugins Prettier QWeb ReactJS shell Spring Framework ubuntu Visual Studio Visual Studio Code wordpress yaml

Entradas recientes

  • Firebase
  • _Lodash
  • Crear un entorno de desarrollo WordPress con Docker, en una patada
  • docker-compose
  • Dockerfile
  • Docker
  • TypeScript
  • Cómo tener distintas versiones de node en tu equipo?
  • Heroku
  • Node JS

Copyright © 2021 · GeekeZonia · Aviso Legal · Política de Cookies · Política de Privacidad · Iniciar sesión

Utilizamos cookies propias y de terceros para ofrecer nuestros servicios, recoger información estadística e incluir publicidad. Si continua navegando acepta su instalación y uso. Leer Mas. Acepta
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Siempre activado

Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.

Non-necessary

Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.

SAVE & ACCEPT