• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

Geekebrains

Para programadores, maker y geeks en general

  • Inicio
  • Code Brains
  • Zona Makers!
  • Code & Beers
  • GeekeHistorias
  • GeekeBlocks
  • Qué es …?
You are here: Home / Code Brains / Spring Framework de Java

2 febrero, 2020 Por admin8049

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

Filed Under: Code Brains Tagged With: Java, MVC, Spring Framework

Previous Post: « Expresiones regulares
Next Post: Proyecto de Control remoto RC con arduino y nRF24L01 »

Primary Sidebar

Categorías

  • Code & Beers
  • Code Brains
  • Cómo …?
  • Experimentos
  • GeekeBlocks
  • GeekeHistorias
  • Noticias Geek
  • Proyectos
  • Qué es …?
  • Quién es …?
  • Zona Junior!
  • Zona makers!

Etiquetas

Antipatrones de diseño de software Arduino Arquitectura de software base64 Bases de Datos cert Certificados Digitales Clean Code control de acceso DBeaver Diseño de Software docker docker-compose Domain Drive Design Edición de video https IDE Java javascript jest JSON lenguajes de programación Librerías de JavaScript MongoDb MySQL NodeJS NoSQL odoo openssl Oracle package.json Patrones de Diseño de Software pem plugins Postgres Prettier ReactJS seguridad Serverless shell SSL testing TypeScript utilidades de software Visual Studio Code

Entradas recientes

  • CAPTCHA y por qué es importante para la seguridad en línea
  • Cómo mokear una clase que se instancia dentro de otra que necesitas testear y no se pasa por injección?
  • tsconfig paths con Typescript en Serverless
  • Serverless, un framework para todos los proveedores
  • Serverless, otro enfoque de desarrollo
  • Que es currying en Javascript
  • Noticias Junio 2023. Vuelta a la oficina, Million.js, Linux Azure, Apple Vision, Java 21…
  • 23.3 WS:IA-JS Creando un Blog en React con chatGPT.
  • 23.2 IA. Cómo va a afectar a nuestros empleos?
  • 23.1 IA. En que punto estamos y como hemos llegado hasta aquí.
Jesús A. Carballo Santaclara

Empezé trasteando en los 80' con un ZX espectrum, después pasé al potente "PC 8086" (jeje...). He trabajado haciendo software para la administración pública, para Hospitales, el sector de la Automoción, el sector Bancario, en algún e-Commerce de alguna multinacional y he emprendido en robótica educativa y en buscadores web.
Trabajo de forma profesional en esto de los ordenadores desde hace mas de 25 años espero poder contarte alguna cosa interesante.

Footer

Copyright © 2025 · GeekeZonia · Aviso Legal · Política de Cookies · Política de Privacidad · Log in