Spring Boot 服务器无法启动,企业应用程序

Posted

技术标签:

【中文标题】Spring Boot 服务器无法启动,企业应用程序【英文标题】:Springboot server wont start, Enterprise application 【发布时间】:2020-11-05 14:01:11 【问题描述】:

您好,我是当前的学生和完全的 JEE 菜鸟,我使用 mvn 创建了一个多模块项目,当我从我的 application.java 启动服务器时,我收到了这个错误,我不太确定如何修复它..我得到了即将举行考试,我压力很大,因此非常感谢您的帮助!抱歉,如果这是一个小问题和/或问题。

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.1.4.RELEASE)

[INFO] Starting Application on DESKTOP-4KFU8LQ with PID 9036 (C:\Users\Kevin\Desktop\mockExam\frontend\target\classes started by Kevin in C:\Users\Kevin\Desktop\mockExam)
[INFO] No active profile set, falling back to default profiles: default
[INFO] Bootstrapping Spring Data repositories in DEFAULT mode.
[INFO] Finished Spring Data repository scanning in 19ms. Found 0 repository interfaces.
[INFO] Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$ce869900] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[INFO] Bean 'org.joinfaces.autoconfigure.javaxfaces.JsfBeansAutoConfiguration$Jsf2_3AutoConfiguration' of type [org.joinfaces.autoconfigure.javaxfaces.JsfBeansAutoConfiguration$Jsf2_3AutoConfiguration$$EnhancerBySpringCGLIB$$dea1e2b5] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[INFO] Bean 'org.joinfaces.autoconfigure.javaxfaces.JsfBeansAutoConfiguration' of type [org.joinfaces.autoconfigure.javaxfaces.JsfBeansAutoConfiguration$$EnhancerBySpringCGLIB$$92d067bb] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
[INFO] Tomcat initialized with port(s): 8080 (http)
[INFO] Initializing ProtocolHandler ["http-nio-8080"]
[INFO] Starting service [Tomcat]
[INFO] Starting Servlet engine: [Apache Tomcat/9.0.17]
[INFO] At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
[INFO] Initializing Spring embedded WebApplicationContext
[INFO] Root WebApplicationContext: initialization completed in 1929 ms
[INFO] Resolving classes for com.sun.faces.config.FacesInitializer took 1.038s
[INFO] Initializing Mojarra 2.3.8 ( 20181116-0037 55af8b79ca53ec2df566f9c08a430259d30f9ba5) for context ''
[INFO] JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
[WARN] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
[INFO] Stopping service [Tomcat]
[INFO] 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
[ERROR] Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'flyway' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:456)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
    at org.example.mockexam.Application.main(Application.java:13)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.flywaydb.core.Flyway]: Factory method 'flyway' threw exception; nested exception is java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622)
    ... 21 common frames omitted
Caused by: java.lang.IllegalStateException: Cannot find migrations location in: [classpath:db/migration] (please add migrations or check your Flyway configuration)
    at org.springframework.util.Assert.state(Assert.java:94)
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.checkLocationExists(FlywayAutoConfiguration.java:194)
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration.flyway(FlywayAutoConfiguration.java:153)
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$4e8466a0.CGLIB$flyway$0(<generated>)
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$4e8466a0$$FastClassBySpringCGLIB$$92d06f5a.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:363)
    at org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration$FlywayConfiguration$$EnhancerBySpringCGLIB$$4e8466a0.flyway(<generated>)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
    ... 22 common frames omitted

Process finished with exit code 1

【问题讨论】:

Spring(boot) != JavaEE 9and JEE 是错误的缩写 我看到您正在使用 flyway 进行数据库架构升级。您是否创建了 src/main/resources/db/migration/ 目录? 是的,gyazo.com/f64d8ff42de1b51a20a0ecf36dda7748 @Kukeltje JavaEE 9 也是一个错误的缩写。 这应该是一个((移位不起作用)和右括号,)丢失了。 【参考方案1】:

在 [classpath:db/migration] 中找不到迁移位置

添加适当的迁移,或者如果它们位于正确的位置,请检查它们的命名。

迁移的正确位置,即classpath:db/migration,是src\main\resources\db\migrations 文件夹。

正确的命名逻辑可以在here找到。

【讨论】:

好的,谢谢,这是我的后端部分,你有什么问题吗? gyazo.com/a713cd331e84eab2c53c90737b091393 db.migration 只有一个包吗?应该是resources -&gt; db -&gt; migration 你是对的,它只是一个包裹!我把它分开了,现在我得到了这个:在类路径资源[org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]中定义的名称为'flywayInitializer'的bean创建错误:init方法的调用失败;嵌套异常是 java.lang.RuntimeException: Driver org.postgresql.Driver 声称不接受 jdbcUrl, jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE,这是我的 application.yml 文件:gyazo.com/7149648e598b69924d2904e9a3242428 你有 h2:mem 数据库,你告诉 Spring 它应该使用的驱动程序是 Postgresql?顺便说一句,如果对您的问题有帮助,点赞并接受答案总是很好的。 是的,我只是看不到我在哪里说过。我是这个论坛的新手,所以我的投票不会公开显示,哈哈【参考方案2】:

错误日志描述“在 [classpath:db/migration] 中找不到迁移位置(请添加迁移或检查您的 Flyway 配置)”请显示有关 Flyway 配置的更多信息

【讨论】:

这不正确吗? gyazo.com/f64d8ff42de1b51a20a0ecf36dda7748【参考方案3】:

我假设您还没有任何 flyway 迁移,如果是这样,您现在可以从 gradle 或 maven 中删除 flyway 依赖项,它应该有助于启动应用程序。 如果您决定要进行迁移,则添加 flyway back,并在类路径中创建名为 db/migrations 的文件夹,并在其中添加迁移文件。

【讨论】:

没有足够的声望直接在帖子上发布图片,但是你去:gyazo.com/f64d8ff42de1b51a20a0ecf36dda7748 这看起来差不多。尝试将这些 flyway 设置也添加到 application.properties: spring.flyway.check-location=true # 是否启用 flyway。 spring.flyway.locked=false spring.flyway.encoding=UTF-8 #迁移脚本的位置。 spring.flyway.locations=classpath:db/migration spring.flyway.out-of-order=false # 更新模式 spring.flyway.schemas=your_schema spring.flyway.sql-migration-suffixes=.sql spring.flyway.sql -migration-prefix=spring.flyway.table=table_for_migration_tracking spring.flyway.validate-on-migrate=false

以上是关于Spring Boot 服务器无法启动,企业应用程序的主要内容,如果未能解决你的问题,请参考以下文章

企业级spring-boot案例-Spring Boot 启动时的运行方法

企业级spring-boot案例-Spring Boot 启动时的运行方法

企业级spring-boot案例-Spring Boot 启动时的运行方法

企业级spring-boot案例-Spring Boot 启动时的运行方法

企业分布式微服务云SpringCloud SpringBoot mybatis Spring Boot开发Web应用

无法启动 Spring Boot 应用程序