Java 我无法启动ServletWebServerApplicationContext,因为即使使用@springbootapplication也缺少ServletWebServerFactory bean

Java 我无法启动ServletWebServerApplicationContext,因为即使使用@springbootapplication也缺少ServletWebServerFactory bean,java,spring,Java,Spring,这是我的主课 即使我正在使用springbootApplication注释自动关联所有依赖项,也会出现此错误 @EntityScan(basePackages = {"com.valentine.model","com.valentine.messenger"}) @SpringBootApplication(scanBasePackages = {"com.valentine.gram", "com.valentine.service", "com.valentine"}) @Enab

这是我的主课 即使我正在使用springbootApplication注释自动关联所有依赖项,也会出现此错误

@EntityScan(basePackages = {"com.valentine.model","com.valentine.messenger"})
@SpringBootApplication(scanBasePackages = {"com.valentine.gram",
    "com.valentine.service", "com.valentine"})
@EnableJpaRepositories("com.valentine.dao")
@EnableTransactionManagement
public class MainApp {

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

}
下面是我的堆栈跟踪和pom文件,这是一个模块化项目,所以我发布了主pom文件

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-11-09 23:10:47.131 ERROR 9266 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.0.8.RELEASE.jar:5.0.8.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:762) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:398) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1258) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at com.valentine.gram.MainApp.main(MainApp.java:19) [classes/:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:204) ~[spring-boot-2.0.4.RELEASE.jar:2.0.4.RELEASE]
    at  
现在pom文件在下面

  <dependency>
            <groupId>com.valentine.mygram</groupId>
            <artifactId>main-app</artifactId>
            <version>${project.version}</version>
        </dependency>

        <!--spring-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-test</artifactId>
            <version>2.0.4.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!--servlets-->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${javax.servlet-api.version}</version>
        </dependency>

任何关于问题可能是什么以及如何解决问题的建议

正如我在spring boot中所知道的,没有必要使用额外的注释,如

@EntityScan(basePackages = {"com.valentine.model","com.valentine.messenger"})
@SpringBootApplication(scanBasePackages = {"com.valentine.gram",
    "com.valentine.service", "com.valentine"})
@EnableJpaRepositories("com.valentine.dao")
我认为@SpringBootApplication足以处理所有这些注释

我不知道你为什么在SpringBoot中使用这些依赖项

     <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>${spring.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-test</artifactId>
                <version>2.0.4.RELEASE</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>${spring.version}</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.version}</version>
        </dependency>
所有这些依赖项都是针对SpringMVC的,而不是针对SpringBoot的!在SpringBoot中,不需要提及依赖项的版本。像

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${javax.servlet-api.version}</version>
     </dependency>
你只能这样写,spring boot会自动处理

 <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
    </dependency>

正如我所知,在SpringBoot中,不需要使用像这样的额外注释

@EntityScan(basePackages = {"com.valentine.model","com.valentine.messenger"})
@SpringBootApplication(scanBasePackages = {"com.valentine.gram",
    "com.valentine.service", "com.valentine"})
@EnableJpaRepositories("com.valentine.dao")
我认为@SpringBootApplication足以处理所有这些注释

我不知道你为什么在SpringBoot中使用这些依赖项

     <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>${spring.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-test</artifactId>
                <version>2.0.4.RELEASE</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>${spring.version}</version>
                <scope>test</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring.version}</version>
            </dependency>

            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${spring.version}</version>
            </dependency>
            <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.version}</version>
        </dependency>
所有这些依赖项都是针对SpringMVC的,而不是针对SpringBoot的!在SpringBoot中,不需要提及依赖项的版本。像

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>${javax.servlet-api.version}</version>
     </dependency>
你只能这样写,spring boot会自动处理

 <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
    </dependency>

你检查过这个吗?是的,它建议spring:main:web应用程序类型:无,但我的是一个web应用程序,所以我不能对web应用程序说无type@Deadpool那么,还有什么其他选择是的,问题是从属关系的版本应该从boots repo获得,而不是手写。想法来自您的回答谢谢您检查过这个吗是的建议spring:main:web应用程序类型:无但我的是web应用程序,所以我不能对web应用程序说无type@Deadpool那么,还有什么其他选择是的,问题是从属关系的版本应该从boots repo获得,而不是手写。这个想法来自您的回答谢谢