• ff4j web console 配置说明


    web console 可以让我们方便的通过界面管理ff4j,以下是一些简单的说明
    详细参考github 文档

    spring boot 集成

    • pom.xml
     
    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>com.dalongrong</groupId>
        <artifactId>webconsole-ff4j</artifactId>
        <version>1.0-SNAPSHOT</version>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.15.RELEASE</version>
        </parent>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <java.version>1.8</java.version>
            <ff4j.version>1.8.4</ff4j.version>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.ff4j</groupId>
                <artifactId>ff4j-web</artifactId>
                <version>${ff4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.ff4j</groupId>
                <artifactId>ff4j-spring-boot-starter</artifactId>
                <version>${ff4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.thymeleaf</groupId>
                <artifactId>thymeleaf</artifactId>
                <version>3.0.2.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.ff4j</groupId>
                <artifactId>ff4j-store-springjdbc</artifactId>
                <version>${ff4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-dbcp2</artifactId>
            </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </project>
    • 配置
      application.properties 文件
      添加了jdbc datasource
     
    spring.datasource.name=ff4j_db
    spring.datasource.url=jdbc:mysql://localhost:3306/ff4j_v1
    spring.datasource.driverClassName=com.mysql.jdbc.Driver
    spring.datasource.username=root
    spring.datasource.password=dalongrong
    spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    • servlet 配置
      主要是关于web console 的servlet 配置
      FF4jServletConfig.java
     
    package com.dalong;
    import org.ff4j.FF4j;
    import org.ff4j.spring.boot.autoconfigure.FF4JConfiguration;
    import org.ff4j.web.FF4jDispatcherServlet;
    import org.ff4j.web.embedded.ConsoleServlet;
    import org.springframework.boot.autoconfigure.AutoConfigureAfter;
    import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
    import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
    import org.springframework.boot.web.servlet.ServletRegistrationBean;
    import org.springframework.boot.web.support.SpringBootServletInitializer;
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    @Configuration
    @ConditionalOnClass({ConsoleServlet.class, FF4jDispatcherServlet.class})
    @AutoConfigureAfter({FF4JConfiguration.class})
    public class FF4jServletConfig
            extends SpringBootServletInitializer
    {
        @Bean
        public ServletRegistrationBean ff4jDispatcherServletRegistrationBean(FF4jDispatcherServlet ff4jDispatcherServlet)
        {
            return new ServletRegistrationBean(ff4jDispatcherServlet, new String[] { "/ff4j-web-console/*" });
        }
        @Bean
        @ConditionalOnMissingBean
        public FF4jDispatcherServlet getFF4jDispatcherServlet(FF4j ff4j)
        {
            FF4jDispatcherServlet ff4jConsoleServlet = new FF4jDispatcherServlet();
            ff4jConsoleServlet.setFf4j(ff4j);
            return ff4jConsoleServlet;
        }
    } 
    • spring boot 入口
      Application.java 注意对于jdbc DataSource 通过bean 的覆盖方式处理
     
    package com.dalong;
    import net.bytebuddy.asm.Advice;
    import org.ff4j.FF4j;
    import org.ff4j.springjdbc.store.EventRepositorySpringJdbc;
    import org.ff4j.springjdbc.store.FeatureStoreSpringJdbc;
    import org.ff4j.springjdbc.store.PropertyStoreSpringJdbc;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.CommandLineRunner;
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.ComponentScan;
    import javax.sql.DataSource;
    @SpringBootApplication
    @ComponentScan(value = {"org.ff4j.spring.boot.web.api", "org.ff4j.services", "org.ff4j.aop", "org.ff4j.spring","com.dalong"})
    public class Application implements CommandLineRunner {
        @Autowired
        private DataSource dataSource;
        @Autowired
        FF4j ff4j;
        public static void main(String[] args) {
            SpringApplication.run(Application.class);
        }
        @Override
        public void run(String... strings) throws Exception {
                ff4j.setFeatureStore(new FeatureStoreSpringJdbc(dataSource));
                ff4j.setPropertiesStore(new PropertyStoreSpringJdbc(dataSource));
                ff4j.setEventRepository(new EventRepositorySpringJdbc(dataSource));
                ff4j.audit(true);
                ff4j.autoCreate(true);
        }
    }
     
     

    运行效果

    • 启动docker-compose for mysql
      mysql数据库
     
    docker-compose up -d  
    • 启动应用
    mvn spring-boot:run
    • 效果

    访问地址:http://localhost:8080/ff4j-web-console/home

    参考资料

    https://stackoverflow.com/questions/37439369/spring-boot-and-thymeleaf-3-0-0-release-integration/39758600
    https://github.com/ff4j/ff4j/wiki/Web-Concepts

  • 相关阅读:
    python基础学习(十一)公共方法
    python基础学习(九)字典
    python基础学习(八)元组
    python基础学习(七)列表
    python基础学习(六)函数基础
    python基础学习(五)while循环语句
    python基础学习(四)if判断语句
    python基础学习(三)变量和类型
    python基础学习(二)注释和算术运算符
    用CSS3制作50个超棒动画效果教程
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/12740537.html
Copyright © 2020-2023  润新知