3
我試圖從xml配置移動到java配置。應用程序可以沒有任何錯誤地開始,但是當內容不同時,jsp返回$ END $。
我相信我的地方做了一些愚蠢的錯誤,也沒有拋出的異常
注:使用XML配置的一切,當工作正常
配置類
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView;
@Configuration
@EnableWebMvc
@ComponentScan("app.test.portal")
public class PortalConfiguration {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
初始化器類
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
public class PortalInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[]{PortalConfiguration.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[]{"/"};
}
}
控制器
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class IndexController {
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String index() {
return "index";
}
}
指向可能是這個職位將幫助你: - http://stackoverflow.com/questions/24014919/converting -spring-xml-file-to-spring-configuration-class – SaviNuclear
@Henry,這個問題在2個月前問過了,我想我可能會共享一個解決方案。現在你提到了,我會將其移至答案 –