【发布时间】:2016-03-30 08:53:27
【问题描述】:
如何将下面带有不同注释的两个控制器合并到一个控制器中? 我正在尝试设置一个 Spring Boot 应用程序,该应用程序在前端使用 AngularJS,并在基于 MySQL 的 Spring Security 身份验证后端。
为此,我一直在研究the code in this example which links AngularJS with Spring Boot Security and authentication from server-side config 和this other example, which uses MySQL-based authentication to a Spring Boot backend of an app that uses Thymeleaf as the front end. 这两个示例应用程序都已在我的devbox 中启动并运行,但现在我需要合并两个应用程序的后端,以便/user url 模式可用于前端应用程序的后端身份验证,同时还导致使用 MySQL 后端示例中的 dataSource bean 完成身份验证。
问题是一个应用中的控制器使用@SpringBootApplication和@Controller注解,而另一个应用中的控制器使用@Configuration、@EnableAutoConfiguration和@ComponentScan注解。 如何协调这些注释,以便一个控制器可以包含当前在两个应用程序之间隔离的代码?
这是第一个应用程序中控制器的注释:
@SpringBootApplication
@Controller
public class UiApplication {
//lots of code
}
这是第二个应用程序中控制器的注释:
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends WebMvcConfigurerAdapter {
//lots of code
}
【问题讨论】:
标签: java spring spring-mvc spring-security spring-boot