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 response_code = new HashMap(); @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 webserver上运行,对我来说很奇怪的是,当我将这段代码添加到我的pom时,index.jsp将完全出现在浏览器中但当我删除它时,它为我的控制器提供404未找到的URL。 为什么即使我的项目不是春季启动项目需要spring boot starter parent? 我认为下面的代码与spring boot有关,因为我的项目不是spring boot而是spring mvc,不需要它。 但没有在pom中添加此代码它有问题:

  org.springframework.boot spring-boot-starter-parent 1.5.1.RELEASE  

CHILD POM常见配置提供了场所 。 例如

DependenciesProperties

eg这里是父POM配置1.4.2.RELEASE spring-boot-dependencies ,它是spring-boot-starter-parent

  5.13.4 2.7.7 1.9.44 1.3.0 1.8.9 2.5.0 3.9.3 2.1.4 2.3.4 

child POM的共同属性

     org.springframework.boot spring-boot 1.4.2.RELEASE   org.springframework.boot spring-boot test-jar 1.4.2.RELEASE   

孩子的共同依赖

如果您可以提供更多信息,例如您的pom完整性,我们可以进一步了解并帮助您。

另一方面,父pom spring-boot-starter-parent包含完整的依赖项(mvc,cache,jpa)和commons属性,以保持良好一致性的依赖项版本,以便在项目或/和子模块中使用。

基本上,你可以根据需要在你的pom.xml中添加一些启动器(web,jpa,batch ….)对于你的例子,你可以在你的pom.xml中添加一个启动mvc而不添加其他依赖项,所以你的pom.xml可以是这样的:

   org.springframework.boot spring-boot-starter-parent 1.5.9.RELEASE    org.springframework.boot spring-boot-starter-web    1.8     org.springframework.boot spring-boot-maven-plugin    

Spring Boot提供了许多“Starters”,可以将jar添加到类路径中。 对于前者 spring-boot-starter-security,spring-boot-starter-web等。“spring-boot-starter-parent”是一个特殊的启动器,提供有用的Maven默认值,即它自动添加所有必需的jar和其他东西。 它还提供了一个依赖项管理部分,以便您可以省略在pom.xml中使用的依赖项的版本标记。 对于前者 假设您要使用spring boot创建Web应用程序,因此需要添加以下内容。

   org.springframework.boot spring-boot-starter-web   

现在请注意,标签被省略了。 所以最终“spring-boot-starter-parent”默认添加了很多东西,所以我们不必担心这些事情。