search
HomeJavajavaTutorialHow to create springboot test class annotations

    Create a TextHello class

    How to create springboot test class annotations

    How to create springboot test class annotations

    The code for the TextHello class is as follows

     @Controller
    @RequestMapping("/hello")
    public class TextHello {
    @GetMapping("/hello")
    @ResponseBody
    public String hello(){
    return "hello,程程呀";
    }
    }

    I added the dependency in the pom.xml file as follows

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    </dependency>

    The result in the browser is as follows:

    How to create springboot test class annotations

    ##Automatic configuration: pom.xml spring-boot-dependencies: The core dependencies are in the parent project! We do not need to specify the version number when writing or introducing springboot dependencies because there are these version warehouse starters

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
    </dependency>

    starter: it is the startup scenario of springboot, such as spring-boot-starter-web, he It will help us automatically import all dependencies in the web environment. And springboot will turn all scenarios into starters

    Annotations

    @SpringBootApplication: Contains @configuration, @ComponentScan, @EnableAutoConfiguration usually on the main class
    @SpringBootConfiguration : springboot configuration
    @Configuration : spring configuration class
    @Component : Description this is also a spring component
    @EnableAutoConfiguration : Automatic configuration
    @AutoConfigurationPackage : Automatic configuration package
    @ResponseBody: Return The information is data in json format. Generally speaking, the @RestRestController annotation will be used directly.
    @CrossOrigin: Solve cross-domain issues. If no special processing is done, the general @CrossOrigin will be added to the control layer class. Unless a gateway is introduced, there is no need to use annotations to resolve cross-domain issues.
    @MapperScan: In the past, @Mapper was used to define mappers one by one. With @MapperScan, you only need to specify the mapper package, and there is no need to use @Mapper annotations one by one.
    @EnableScheduling: Enable scheduled tasks, used on classes.
    @Value: Dynamically inject the value of the external configuration file. .
    @Transactional: Declarative transaction annotation.
    @Data: After using the annotations under lombok, there is no need to write the getter and setter methods of the entity class.
    @RestController: used to annotate control layer components, including @Controller and @ResponseBody.
    All automatic configuration of springboot is scanned and loaded at startup: spring.factories All automatic configuration classes are in it, but they may not take effect. To judge the corresponding start, there is Only when you have the corresponding launcher, the automatic assembly will take effect, and then the configuration will be successful.

    Main startup class

    @SpringBootApplication: Mark this class as a springboot application: all resources under the startup class are imported springboot understanding: automatic assembly, run() fully takes over the springMVC configuration!

    How to create springboot test class annotations

    Static: store static resources, such as: css, js, pictures Templates: template file application.porperties: springboot configuration file

    Configuration file format

    properties file: key-value format

    How to create springboot test class annotations

    yml file: ladder-shaped properties file

    How to create springboot test class annotations

    Difference

    • #.yml format does not support @PropertySource annotation import configuration.

    • When there are the same attributes in the properties file and the yml file, the properties file has a higher priority than the yml file

    • Look at the picture above: The formats of the two configuration files are different. When they are configured identically, the properties have priority over the yml file. However, it is recommended to use the yml file because the structure of this file is clearer.

    The above is the detailed content of How to create springboot test class annotations. For more information, please follow other related articles on the PHP Chinese website!

    Statement
    This article is reproduced at:亿速云. If there is any infringement, please contact admin@php.cn delete
    How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?How do I use Maven or Gradle for advanced Java project management, build automation, and dependency resolution?Mar 17, 2025 pm 05:46 PM

    The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

    How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?How do I create and use custom Java libraries (JAR files) with proper versioning and dependency management?Mar 17, 2025 pm 05:45 PM

    The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

    How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?How do I implement multi-level caching in Java applications using libraries like Caffeine or Guava Cache?Mar 17, 2025 pm 05:44 PM

    The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

    How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?How can I use JPA (Java Persistence API) for object-relational mapping with advanced features like caching and lazy loading?Mar 17, 2025 pm 05:43 PM

    The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

    How does Java's classloading mechanism work, including different classloaders and their delegation models?How does Java's classloading mechanism work, including different classloaders and their delegation models?Mar 17, 2025 pm 05:35 PM

    Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa

    See all articles

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. How to Fix Audio if You Can't Hear Anyone
    4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
    WWE 2K25: How To Unlock Everything In MyRise
    1 months agoBy尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Dreamweaver Mac version

    Dreamweaver Mac version

    Visual web development tools

    SublimeText3 English version

    SublimeText3 English version

    Recommended: Win version, supports code prompts!

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    Atom editor mac version download

    Atom editor mac version download

    The most popular open source editor

    SAP NetWeaver Server Adapter for Eclipse

    SAP NetWeaver Server Adapter for Eclipse

    Integrate Eclipse with SAP NetWeaver application server.