kullanarak, ben yani dinlenme hizmet ve normal isteklerden bir RootContextConfiguration
ve diğer iki bağlam yapılandırma dosyaları var; RestServletContextConfiguration
ve WebServletContextConfiguration
.SpringMVC, iki bağlamları ve istirahat Hizmet için iki görev dağıtıcılarınızı ve normal içeriğini benim SpringMVC proje yapılandırmada
, ben aşağıdaki kodda olduğu gibi uygulamayı işe koşulması ediyorum.
public class Bootstrap implements WebApplicationInitializer
{
@Override
public void onStartup(ServletContext container) throws ServletException
{
container.getServletRegistration("default").addMapping("/resource/*");
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(RootContextConfiguration.class);
container.addListener(new ContextLoaderListener(rootContext));
AnnotationConfigWebApplicationContext restContext = new AnnotationConfigWebApplicationContext();
restContext.register(RestServletContextConfiguration.class);
DispatcherServlet restServlet = new DispatcherServlet(restContext);
restServlet.setDispatchOptionsRequest(true);
ServletRegistration.Dynamic springRestDispatcher = container.addServlet("springRestDispatcher", restServlet);
springRestDispatcher.setLoadOnStartup(1);
springRestDispatcher.addMapping("/api/*");
AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
webContext.register(WebServletContextConfiguration.class);
DispatcherServlet webServlet = new DispatcherServlet(webContext);
ServletRegistration.Dynamic springWebDispatcher = container.addServlet("springWebDispatcher", webServlet);
springWebDispatcher.setLoadOnStartup(2);
springWebDispatcher.setMultipartConfig(new MultipartConfigElement(null, 20_971_520L, 41_943_040L, 512_000));
springWebDispatcher.addMapping("/*");
}
}
Ben /API/arabalar
@RestController
@RequestMapping("/cars")
class CarRestController{}
Ve çözümlemek gerekir/arabalar Ancak
@Controller
@RequestMapping("/cars")
class CarController{}
için, dağıtım nedeniyle belirsiz eşleme başarısız çözmek için. CarRestController
'un @RequestMapping('/api/cars')
ile eşlemesini değiştirirseniz, o denetleyiciye /api/api/arabalar yoluna erişebilir (çift api öneki). Ama ne istediğim CarRestController
/API/otomobil ile erişmek mümkün olmaktır.
benim hedefe ulaşmak için ne yapmalıyım ?. Yardımınız için çok teşekkür ederiz.
için
kalan kontrol MVC kontrol ile aynı paket içinde yer var mı? Ve herhangi bir bağlam için bileşen tarama ayarlarınız nedir? –
** RootContext ** -> '@ComponentScan (basePackages =" xxx.spring ", excludeFilters = {@ ComponentScan.Filter (Controller.class), @ ComponentScan.Filter (RestController.class)})'. ** RestServletContext ** -> @ComponentScan (basePackages = { "xxx.spring"}, useDefaultFilters = kapalı, includeFilters = @ ComponentScan.Filter (RestController.class)). ** WebServletContext ** -> @ComponentScan (basePackages = {"xxx.spring"}, useDefaultFilters = false, includeFilters = @ ComponentScan.Filter (RestController.class)) – Johna