Create a TextHello class
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:
<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 startersAnnotations@SpringBootApplication: Contains @configuration, @ComponentScan, @EnableAutoConfiguration usually on the main class
@SpringBootConfiguration : springboot configurationAll 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!
@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.
- #.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!

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

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

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

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]

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


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.