클라이언트 코드에 스프링 REST 서버 (v3.2)와 AngularJS가 있습니다.함께 작동하도록 스프링과 각도를 구성하는 방법
기본 시나리오에서 사용자가 기본 도메인 .com으로 이동하면 index.html이 다시 전송되고 및 그 지점에서 Angular가 통신을 관리합니다.
내 질문은 입니다. 1. 각도 파일을 반환하도록 Spring을 설정하는 방법. 2. 사용자가 기본 도메인으로 이동하지 않고 .com/books/moby-dick으로 이동하여이라고 가정 한 Moby-Dick 북의 JSON 표현을 반환하는 상황을 처리하는 방법 클라이언트가
좋은 자습서를 높이 평가할 것입니다. 이 내 웹 initialzer 클래스입니다 :
public class WebAppInitializer implements WebApplicationInitializer {
private static Logger LOG = LoggerFactory.getLogger(WebAppInitializer.class);
@Override
public void onStartup(ServletContext servletContext) {
WebApplicationContext rootContext = createRootContext(servletContext);
configureSpringMvc(servletContext, rootContext);
FilterRegistration.Dynamic corsFilter = servletContext.addFilter("corsFilter", CORSFilter.class);
corsFilter.addMappingForUrlPatterns(null, false, "/*");
// configureSpringSecurity(servletContext, rootContext);
}
private WebApplicationContext createRootContext(ServletContext servletContext) {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
// rootContext.register(CoreConfig.class, SecurityConfig.class);
rootContext.register(CoreConfig.class);
servletContext.addListener(new ContextLoaderListener(rootContext));
servletContext.setInitParameter("defaultHtmlEscape", "true");
return rootContext;
}
private void configureSpringMvc(ServletContext servletContext, WebApplicationContext rootContext) {
AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext();
mvcContext.register(MVCConfig.class);
mvcContext.setParent(rootContext);
ServletRegistration.Dynamic appServlet = servletContext.addServlet(
"webservice", new DispatcherServlet(mvcContext));
appServlet.setLoadOnStartup(1);
Set<String> mappingConflicts = appServlet.addMapping("/");
if (!mappingConflicts.isEmpty()) {
for (String s : mappingConflicts) {
LOG.error("Mapping conflict: " + s);
}
throw new IllegalStateException(
"'webservice' cannot be mapped to '/'");
}
}
이 내 MVC 구성 파일입니다 : 이것에 대해 다음을위한 # 1 방법
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.yadazing.rest.controller"})
public class MVCConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
}
재미 있고 아프다. 감사 – special0ne