如果我使用xml配置文件(web.xml和spring-servlet.xml),我正在尝试小春天项目并遇到问题一切都很好。如果我使用java注释,问题出现了:(
我很困惑为什么intellij想法没有在我的webapp文件夹中显示我的网页浏览量。 Not show jsp file (pressed Ctrl + space) 并且无法解析我的控制器类Cannot resolve var name
中的任何变量名称### Controller CLASS ###
@Controller
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(ModelMap modelMap) {
modelMap.addAttribute("message", "Hello, from java class");
return "welcome";
}
}
配置类
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.toskbilisim")
public class HomeConfiguration extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
@Bean
public MessageSource messageSource(){
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages");
return messageSource;
}
}