spring-boot-starter-parent在pom文件中究竟做了什么?
我正在开发一个项目,它不是Spring boot,而是Spring mvc。我的意思是,例如,在我的项目中没有这样的类:
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
我有这三个类用于spring mvc的配置文件:
@Import(WebSocketConfig.class)
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "......")
public class MainConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/Content/**")
.addResourceLocations("/Content/");
registry.addResourceHandler("/Scripts/**")
.addResourceLocations("/Scripts/");
}
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver viewResolver
= new InternalResourceViewResolver();
viewResolver.setPrefix("/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
第二:
public class MainInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
public static HashMap<String, String> response_code = new HashMap<String, String>();
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class[] { MainConfiguration.class,
WebSocketConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
return null;
}
@Override
protected String[] getServletMappings() {
return new String[] { "/" };
}
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
Security.addProvider(new BouncyCastleProvider());
servletContext.addListener(new MainContextListener());
System.out.println("MainInitializer.onStartup()");
}}
第三
public class MainContextListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent servletContextEvent) {
System.out.println("Context Initialized");
Security.addProvider(new BouncyCastleProvider());
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
System.out.println("Shutting down!");
}
}
有一个控制器和jsp文件,我已经将其配置为在tomcat Web服务器上运行,对我来说很奇怪的是,当我将这段代码片段添加到我的pom,index时.jsp将完全出现在浏览器中,但是当我删除它时,它会为我的控制器提供404找不到的url。为什么即使我的项目不是弹簧靴项目也需要弹簧靴启动器父级?我认为下面的代码与弹簧靴有关,因为我的项目不是弹簧靴而是弹簧mvc,所以不需要它。但是如果没有在pom中添加此代码,它就有问题:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>