spring-boot-starter-parent在pom文件中做了什么? [英] What does spring-boot-starter-parent exactly do in pom file?

查看:185
本文介绍了spring-boot-starter-parent在pom文件中做了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个不是Spring boot而且还有spring mvc的项目。我的意思是我在我的项目中没有这个类:

I'm developing a project which is not Spring boot but also spring mvc. I mean I don't have this class for example in my project:

@SpringBootApplication
public class Application extends SpringBootServletInitializer {

    public static void main(String[] args) {           
      SpringApplication.run(Application.class, args);
    }

我有这三个类用于spring mvc的配置文件:

I have these three classes for configuration file of 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 webserver上运行,对我来说很奇怪的是,当我将这段代码添加到我的pom时,index.jsp将完全出现在浏览器中,但是当我删除它时,它为我的控制器提供了404找不到的url。为什么即使我的项目不是春季启动项目需要spring boot starter parent?我认为下面的代码与spring boot有关,因为我的项目不是spring boot而是spring mvc,不需要它。但是如果没有在pom中添加此代码就会出现问题:

There is a controller and jsp file and I've configured it to run on tomcat webserver, something is strange for me is that when I add this snippet of code to my pom, index.jsp will appear in browser exactly but when I remove it , it gives 404 not found url for my controller. why is it that even my project is not a spring boot project need spring boot starter parent? I thought below code is related to spring boot and since my project is not spring boot but spring mvc, doesn't need it. but it has problem without this code added in pom:

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.1.RELEASE</version>
    </parent>


推荐答案

它提供了共同配置的地方 for CHILD POM s。
例如。

It provides place for common configuration for CHILD POMs. for e.g.

依赖关系&
属性

对于例如
这是父POM配置 1.4.2.RELEASE spring-boot-dependencies
这是的父级:spring-boot-starter-parent

<properties>
    <activemq.version>5.13.4</activemq.version>
    <antlr2.version>2.7.7</antlr2.version>
    <appengine.version>1.9.44</appengine.version>
    <artemis.version>1.3.0</artemis.version>
    <aspectj.version>1.8.9</aspectj.version>
    <assertj.version>2.5.0</assertj.version>
    <atomikos.version>3.9.3</atomikos.version>
    <bitronix.version>2.1.4</bitronix.version>
    <caffeine.version>2.3.4</caffeine.version>

子POM的常见属性 s

<dependencyManagement>
    <dependencies>
        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <version>1.4.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot</artifactId>
            <type>test-jar</type>
            <version>1.4.2.RELEASE</version>
        </dependency>
        <dependency>

孩子的常见依赖

这篇关于spring-boot-starter-parent在pom文件中做了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆