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:
##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 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! Static: store static resources, such as: css, js, pictures Templates: template file application.porperties: springboot configuration file Configuration file formatproperties file: key-value format yml file: ladder-shaped properties file Difference
@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.
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!