您可以控制允许发出特定DispatcherServlet
个实例的请求吗?我已经定义了两个调度程序,一个用于处理/public/public*
的请求,另一个用于private/private*
。
以下是我的调度员
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
return application.sources(Application.class);
}
@Bean
public DispatcherServlet dispatcherServletPublic() {
return new DispatcherServlet();
}
@Bean
public ServletRegistrationBean dispatcherServletPublicRegistration() {
ServletRegistrationBean registration =
new ServletRegistrationBean(dispatcherServletPublic(), "/public/public*");
registration.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
return registration;
}
@Bean
public DispatcherServlet dispatcherServletPrivate() {
return new DispatcherServlet();
}
@Bean
public ServletRegistrationBean dispatcherServletPrivateRegistration() {
ServletRegistrationBean registration =
new ServletRegistrationBean(dispatcherServletPublic(), "/private/private*");
registration.setName("private");
return registration;
}
}
请求映射。
@RestController
public class RmbOneController {
@RequestMapping("/public-data")
public String publicData() {
return "Here is your data: 42.";
}
@RequestMapping("/private-data")
public String privateData() {
return "Here is your PRIVATE data: 43.";
}
}
这不起作用。我正在使用这两个URL获取Whitelabel错误页面。并非此WAR的上下文根是/
。
http://localhost:8080/private/private-data
http://localhost:8080/public/public-data
还有一些我很困惑的项目
我是这样尝试的,因为它接近我们对servlet映射的处理方式 - 定义哪个servlet类会响应给定的URL。
<servlet-mapping>
<servlet-name>PublicServlet</servlet-name>
<url-pattern>/public/*</url-pattern>
</servlet-mapping>
...
<servlet>
<servlet-name>PublicServlet</servlet-name>
<servlet-class>foo.bar.PublicServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>