Spring Boot: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory bean

前端 未结 27 1224
一整个雨季
一整个雨季 2020-11-28 03:55

I am totally new to Spring and started to do the official guides from this site: https://spring.io/guides

I\'d like to do this guide: https://spring.io/guides/gs/sch

相关标签:
27条回答
  • 2020-11-28 04:45

    The problem it's in this class:

    @ComponentScan
    @EnableAutoConfiguration
    public class Application {
        public static void main(String[] args) {
        //SpringApplication.run(Application.class, args);
        SpringApplication.run(ScheduledTasks.class, args);
        }
    }
    

    The correct way to launch your application is:

    @SpringBootApplication
    @EnableScheduling
    public class Application {
        public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        }
    }
    
    0 讨论(0)
  • 2020-11-28 04:45

    An other cause of this problem is corruption of maven repository jars so you can use the following command to solve the problem :

    mvn dependency:purge-local-repository
    
    0 讨论(0)
  • 2020-11-28 04:47

    Clear repository is one possible solution.

    Windows -> delete all subfolders in the maven repository:

    C:\Users\YourUserName.m2\repository

    0 讨论(0)
  • 2020-11-28 04:49

    If you package it as a single jar and it's non web app try to load app context as below.

    @SpringBootApplication
    
    ApplicationContext ctx = new AnnotationConfigApplicationContext(Main.class);
    

    Or use below plugin to package as a single jar

                 <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
    

    you can specify the external configs by using below command to run

    java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/override.properties
    

    /http://docs.spring.io/spring-boot/docs/current/reference/htmlboot-features-external-config.html#boot-features-external-config-application-property-files

    Note that if you are passing the properties as arguments then don't include @PropertySource("classpath:test.properties") it will override the parameters

    0 讨论(0)
  • 2020-11-28 04:50

    Try this

    @Configuration
    @ComponentScan
    @EnableAutoConfiguration
    public class Application {
        public static void main(String[] args) {
           SpringApplication.run(ScheduledTasks.class, args);
        }
    }
    
    0 讨论(0)
  • 2020-11-28 04:50

    Adding the annotation @SpringBootApplication Before the starter class fixed this problem for me (so in essence, this error message can mean "you don't have a @SpringBootApplication marked class anywhere, you need at least one)

    @SpringBootApplication
    public class AppStarter {
    
        public static void main(String[] args) {
            SpringApplication.run(AppStarter.class, args);
        }
    }
    
    0 讨论(0)
提交回复
热议问题