<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Spring annotation(jrebel.com)

      摘自 https://www.jrebel.com/blog/spring-annotations-cheat-sheet

      August 5, 2021

      Spring Annotations Cheat Sheet

      Java Frameworks
      Developer Productivity

      We've gathered useful annotations developers use and packed them into a one-page Spring annotations cheat sheet. From basic annotations you need to get your project started, to service discovery annotations, we’ve got you covered.

      Related reading: How many developers are actually using Spring? Find out in our 2021 Java Developer Productivity Report.

      Important Spring Annotations

      Here are the most important annotations any Java developer working with Spring should know:

      • @Configuration - used to mark a class as a source of the bean definitions. Beans are the components of the system that you want to wire together. A method marked with the @Bean annotation is a bean producer. Spring will handle the life cycle of the beans for you, and it will use these methods to create the beans.
      • @ComponentScan -use to make sure that Spring knows about your configuration classes and can initialize the beans correctly. It makes Spring scan the packages configured with it for the @Configuration classes.
      • @Import -  If you need even more precise control of the configuration classes, you can always use @import  to load additional configuration. This one works even when you specify the beans in an XML file like it's 1999.
      • @Component - Another way to declare a bean is to mark a class with a @Component annotation. Doing this turns the class into a Spring bean at the auto-scan time.
      • @Service - Mark a specialization of a @Component. It tells Spring that it's safe to manage them with more freedom than regular components. Remember, services have no encapsulated state.
      • @Autowired - To wire the application parts together, use the @Autowired on the fields, constructors, or methods in a component. Spring's dependency injection mechanism wires appropriate beans into the class members marked with @Autowired.
      • @Bean - A method-level annotation to specify a returned bean to be managed by Spring context. The returned bean has the same name as the factory method.
      • @Lookup - tells Spring to return an instance of the method's return type when we invoke it.
      • @Primary - gives higher preference to a bean when there are multiple beans of the same type.
      • @Required - shows that the setter method must be configured to be dependency-injected with a value at configuration time. Use @Required on setter methods to mark dependencies populated through XML. Otherwise, a BeanInitializationException is thrown.
      • @Value - used to assign values into fields in Spring-managed beans. It's compatible with the constructor, setter, and field injection.
      • @DependsOn - makes Spring initialize other beans before the annotated one. Usually, this behavior is automatic, based on the explicit dependencies between beans. The @DependsOn annotation may be used on any class directly or indirectly annotated with @Component or on methods annotated with @Bean.
      • @Lazy - makes beans to initialize lazily. @Lazy annotation may be used on any class directly or indirectly annotated with @Component or on methods annotated with @Bean.
      • @Scope - used to define the scope of a @Component class or a @Bean definition and can be either singleton, prototype, request, session, globalSession, or custom scope.
      • @Profile - adds beans to the application only when that profile is active.

      Armed with these annotations you can make the application come together with a very little effort. Naturally, there are more Spring annotations that you might want to use, but these here are the core of the framework that enables the flexibility Spring is known for!

      Looking to save time on your Java development? Try JRebel free for 10 days.

      Important Spring Boot Annotations

      Let's look at some of the most frequently used annotations in the context of web apps. Most of our readers are either backend engineers or are doing full stack developer jobs. So it makes sense to popularize the Spring Framework annotations that make web development easier.

      @SpringBootApplication

      One of the most basic and helpful annotations, is @SpringBootApplication. It's syntactic sugar for combining other annotations that we'll look at in just a moment. @SpringBootApplication is @Configuration, @EnableAutoConfiguration and @ComponentScan annotations combined, configured with their default attributes.

      @Configuration and @ComponentScan

      The @Configuration and @ComponentScan annotations that we described above make Spring create and configure the beans and components of your application. It's a great way to decouple the actual business logic code from wiring the app together.

      @EnableAutoConfiguration

      Now the @EnableAutoConfiguration annotation is even better. It makes Spring guess the configuration based on the JAR files available on the classpath. It can figure out what libraries you use and preconfigure their components without you lifting a finger. It is how all the spring-boot-starter libraries work. Meaning it's a major lifesaver both when you're just starting to work with a library as well as when you know and trust the default config to be reasonable.

      Important Spring MVC Web Annotations

      The following annotations make Spring configure your app to be a web application, capable of serving the HTTP response.

      • @Controller - marks the class as a web controller, capable of handling the HTTP requests. Spring will look at the methods of the class marked with the @Controller annotation and establish the routing table to know which methods serve which endpoints.
      • @ResponseBody - The @ResponseBody is a utility annotation that makes Spring bind a method's return value to the HTTP response body. When building a JSON endpoint, this is an amazing way to magically convert your objects into JSON for easier consumption.
      • @RestController - Then there's the @RestController annotation, a convenience syntax for @Controller and @ResponseBody together. This means that all the action methods in the marked class will return the JSON response.
      • @RequestMapping(method = RequestMethod.GET, value = "/path") - The @RequestMapping(method = RequestMethod.GET, value = "/path") annotation specifies a method in the controller that should be responsible for serving the HTTP request to the given path. Spring will work the implementation details of how it's done. You simply specify the path value on the annotation and Spring will route the requests into the correct action methods.
      • @RequestParam(value="name", defaultValue="World") - Naturally, the methods handling the requests might take parameters. To help you with binding the HTTP parameters into the action method arguments, you can use the @RequestParam(value="name", defaultValue="World") annotation. Spring will parse the request parameters and put the appropriate ones into your method arguments.
      • @PathVariable("placeholderName") - Another common way to provide information to the backend is to encode it in the URL. Then you can use the @PathVariable("placeholderName") annotation to bring the values from the URL to the method arguments.

      Final Thoughts

      In this post, we've looked at many annotations that a Java developer should know if they want to use the Spring Framework. We've covered the most frequently used and perhaps the most important annotations—from those that enable dependency injection for your components to the ways to bind your code to respond to HTTP requests.

      Download the Spring Annotations Cheat Sheet

      Ready to download our one-page Spring Annotations cheat sheet pdf? Click the button below to get started!

      posted @ 2022-09-22 22:00  harrychinese  閱讀(56)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 四虎成人精品国产永久免费| 福利一区二区不卡国产| 成人一区二区三区激情视频| 久久久久人妻精品一区三寸 | 精品国产一区av天美传媒| 成人乱码一区二区三区av| 日本一区二区a√成人片| 亚洲精品无码在线观看| 精品久久精品久久精品九九 | 国产欧美日韩精品丝袜高跟鞋| 国产精品久久毛片| 国产精品女同一区三区五区| 天堂V亚洲国产V第一次| 色视频不卡一区二区三区| 精品国产女同疯狂摩擦2| 东京热加勒比无码少妇| 性一交一乱一伦| 莱芜市| 91精品久久一区二区三区| 亚洲色婷婷综合开心网| 五月综合激情婷婷六月色窝| 丝袜美腿视频一区二区三区| 日韩av片无码一区二区不卡 | 国产suv精品一区二区四| 韩国精品福利视频一区二区| 久久国产精品老人性| 亚洲中文字幕精品无人区| 亚洲免费观看视频| 久久99久国产麻精品66| 国产女人喷潮视频免费| 日本一区二区三区在线 |观看| 不卡一区二区国产在线| 国产一区二区三区小说| 亚洲区精品区日韩区综合区| 亚洲国产初高中生女av| 国产欧美亚洲精品第一页在线| 视频一区视频二区制服丝袜 | 久久亚洲综合精品成人网| 一本一道av无码中文字幕麻豆 | 佳木斯市| 99久久久无码国产麻豆|