SpringBoot项目启动时默认加载的是resources/application.properties配置文件,所以如果我们在SpringBoot项目中想使用xml的配置方式需要手动配置。SpringBoot官方推荐我们使用注解的配置方式
代码实现
- 创建SpringBoot项目,导入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
- HelloController.java
/**
*控制层
*/
@RestController
public class HelloController {
@Autowired
HelloService helloService;
@GetMapping("/hello")
//@CrossOrigin("http://localhost:8081")
public String hello(){
return helloService.hello();
}
}
- HelloService.java
/**
* 业务层
*/
public class HelloService {
public String hello(){
return "hello";
}
}
- beans.xml