java - 集成 FF4j 的 Spring Boot REST 应用程序。如何修复依赖库的mvc映射?

标签 java spring spring-boot request-mapping ff4j

在我的应用程序中集成 FF4j 我遇到了一系列问题。其最终集成如下recommendation 。 推荐的简短描述是:

  • 删除 thymeleaf 的自动配置;
  • 添加 ff4j-web 使用的旧 thymeleaf 版本 2.1.4.RELEASE
  • 编写一个像 FF4JWebConfiguration 这样的配置类:

    @Configuration
    @ConditionalOnClass({ConsoleServlet.class, FF4jDispatcherServlet.class})
    @AutoConfigureAfter(FF4JConfiguration.class)
    public class FF4JWebConfiguration extends SpringBootServletInitializer {
    
    @Bean
    public ServletRegistrationBean servletRegistrationBean(ConsoleServlet ff4jConsoleServlet) {
      return new ServletRegistrationBean(ff4jConsoleServlet, "/ff4j-console");
    }
    
    @Bean
    @ConditionalOnMissingBean
    public ConsoleServlet getFF4jServlet(FF4j ff4j) {
      ConsoleServlet ff4jConsoleServlet = new ConsoleServlet();
      ff4jConsoleServlet.setFf4j(ff4j);
      return ff4jConsoleServlet;
    }
    
    @Bean
    public ServletRegistrationBean ff4jDispatcherServletRegistrationBean(FF4jDispatcherServlet ff4jDispatcherServlet) {
      return new ServletRegistrationBean(ff4jDispatcherServlet, "/ff4j-web-console/*");
    }
    
    @Bean
    @ConditionalOnMissingBean
    public FF4jDispatcherServlet getFF4jDispatcherServlet(FF4j ff4j) {
      FF4jDispatcherServlet ff4jConsoleServlet = new FF4jDispatcherServlet();
      ff4jConsoleServlet.setFf4j(ff4j);
      return ff4jConsoleServlet;
    }
    

    }

推荐中遗漏的细节是 Maven 排除:

<dependency>
  <groupId>org.thymeleaf</groupId>
  <artifactId>thymeleaf</artifactId>
  <version>2.1.4.RELEASE</version>
  <exclusions>
    <exclusion>
      <artifactId>javassist</artifactId>
      <groupId>org.javassist</groupId>
    </exclusion>
  </exclusions>
</dependency>

但这行不通

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 
14:11:33.605 ERROR o.s.b.SpringApplication - Application run failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.boot.archive.spi.ArchiveException: Could not build ClassFile
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1745)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
  at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)

直到我添加了一些 Maven 排除技巧

<dependency>
  <groupId>org.thymeleaf</groupId>
  <artifactId>thymeleaf</artifactId>
  <version>2.1.4.RELEASE</version>
  <exclusions>
    <exclusion>
      <artifactId>javassist</artifactId>
      <groupId>org.javassist</groupId>
    </exclusion>
  </exclusions>
</dependency>

由于某些数据未加载到用户界面上,我的应用程序已成功启动,但 View 已损坏:

13:38:14.785 INFO  o.f.w.FF4jServlet -   __  __ _  _   _
13:38:14.785 INFO  o.f.w.FF4jServlet -  / _|/ _| || | (_)
13:38:14.785 INFO  o.f.w.FF4jServlet - | |_| |_| || |_| |
13:38:14.785 INFO  o.f.w.FF4jServlet - |  _|  _|__   _| |
13:38:14.785 INFO  o.f.w.FF4jServlet - |_| |_|    |_|_/ |
13:38:14.786 INFO  o.f.w.FF4jServlet -              |__/  v1.8
13:38:14.786 INFO  o.f.w.FF4jServlet -
13:38:14.832 INFO  o.f.w.FF4jServlet - Thymeleaf has been initialized
13:38:14.887 INFO  o.t.TemplateEngine - [THYMELEAF] INITIALIZING TEMPLATE ENGINE
                  13:38:14.971 INFO  o.t.t.AbstractTemplateResolver - [THYMELEAF] INITIALIZING TEMPLATE RESOLVER: org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
13:38:14.972 INFO  o.t.t.AbstractTemplateResolver - [THYMELEAF] TEMPLATE RESOLVER INITIALIZED OK
                  13:38:14.980 INFO  o.t.T.CONFIG - [THYMELEAF] TEMPLATE ENGINE CONFIGURATION:
[THYMELEAF] * Cache Factory implementation: org.thymeleaf.cache.StandardCacheManager
[THYMELEAF] * Template modes:
[THYMELEAF]     * VALIDXML
[THYMELEAF]     * XHTML
[THYMELEAF]     * LEGACYHTML5
[THYMELEAF]     * XML
[THYMELEAF]     * VALIDXHTML
[THYMELEAF]     * HTML5
[THYMELEAF] * Template resolvers (in order):
[THYMELEAF]     * org.thymeleaf.templateresolver.ClassLoaderTemplateResolver
[THYMELEAF] * Message resolvers (in order):
[THYMELEAF]     * [0] customMessageResolver
[THYMELEAF] * Dialect: org.thymeleaf.standard.StandardDialect
[THYMELEAF]     * Prefix: "th"
[THYMELEAF] TEMPLATE ENGINE CONFIGURED OK
13:38:14.981 INFO  o.t.TemplateEngine - [THYMELEAF] TEMPLATE ENGINE INITIALIZED
13:38:15.648 INFO  o.a.c.c.C.[.[.[/] - Initializing Spring DispatcherServlet 'dispatcherServlet'
13:38:15.649 INFO  o.s.w.s.DispatcherServlet - Initializing Servlet 'dispatcherServlet'
13:38:15.713 INFO  o.s.w.s.DispatcherServlet - Completed initialization in 64 ms
13:38:15.746 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/css/font-awesome-3.2.1.css
13:38:15.747 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/css/bootstrap.min.css
13:38:15.747 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/js/jquery/jquery-1.9.1.js
13:38:15.749 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/css/dashboard.css
13:38:15.749 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/css/style.css
13:38:15.750 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/css/bootstrap-responsive.min.css
13:38:15.972 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/js/base.js
13:38:15.973 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/js/bootstrap.js
13:38:15.981 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/img/ff4j.png
13:38:15.989 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/img/flags/flagEnglish.png
13:38:15.989 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/js/ff4j.js
13:38:16.016 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/img/flags/flagMexico.png
13:38:16.030 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/img/flags/flagFrance.png
13:38:16.031 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/img/flags/flagGermany.png
13:38:16.032 WARN  o.s.w.s.PageNotFound - No mapping for GET /static/img/flags/flagJapanese.png 
...

可以通过以下方式修复

registry.addResourceHandler("/static/**")
    .addResourceLocations("classpath:/static/");

但是 ff4j servlet 在我的应用程序中无论如何都不起作用:

WARN  o.s.w.s.PageNotFound - No mapping for GET /features

问题

我检测到 FF4jServlet 初始化并注册了所有必需的 Controller ,但我不清楚为什么它不起作用...... 有什么想法如何解决它吗?

一些项目详细信息:

<parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>2.1.2.RELEASE</version>
  <relativePath/> <!-- lookup parent from repository -->
</parent>

<ff4j.version>1.8.0</ff4j.version>

最佳答案

你有没有尝试过看看

https://github.com/ff4j/ff4j-spring-boot-starter-parent/tree/master/ff4j-spring-boot-sample

有两个控制台。您想访问哪一个?

关于java - 集成 FF4j 的 Spring Boot REST 应用程序。如何修复依赖库的mvc映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55761378/

相关文章:

java - 自动禁用(并恢复)Java 中的异常

java - 如何将击键 Z 添加到 keyPressed(KeyEvent e) 以将球跳跃/重新绘制到新的随机位置? (使用了 KeyListener 演示。)

java - 如何通过 Kotlin Gradle 和 -D 为我的测试提供系统属性

java - Spring Boot日志文件相对于jar目录而不是启动目录

java - Spring 启动 : Overriding CacheManager bean makes cache related properties not work

java - 非法状态异常 : The type registry TypeRegistry (Spring Boot + Spring Loaded + Java 8)

java - websphere MQ 消息的格式是什么

java - Springockito如何?

java - Spring Boot 和 Elastic 客户端 - NoSuchMethodError : org. elasticsearch.action.support.IndicesOptions.ignoreThrottled()Z

java - Spring Boot ClassNotfoundException EmbeddedServletContainerCustomizer