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

前端 未结 27 1452
一整个雨季
一整个雨季 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: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

                 
                    org.springframework.boot
                    spring-boot-maven-plugin
                    
                        
                            
                                repackage
                            
                        
                    
                
    

    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

提交回复
热议问题