积木报表集成问题汇总

622 阅读1分钟

积木报表集成问题汇总

扫包配置

  • 由于配置了scanBasePackages,默认启动application所在的包将不起作用,需要而外指定自己的包的范围进行扫描@component 和@Controller
@SpringBootApplication(exclude = {TransactionAutoConfiguration.class}
        ,scanBasePackages = {"org.jeecg.modules.jmreport","com.xx"}
        )

如果webapp的jsp结构

  • 由于js css等 资源都在webapp下,但是引入积木报表后,静态资源变成了static下,此处冲突

  • 解决方案:覆盖JimuReportConfiguration类的,重写资源映射 “/* ” 改成 "/jimueport/*”

        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            if (oConvertUtils.isEmpty(this.staticLocations)) {
                this.staticLocations = "classpath:/static/";
            } else if (oConvertUtils.isNotEmpty(this.staticLocations) && this.staticLocations.indexOf("classpath:/static/") == -1) {
                this.staticLocations = this.staticLocations + ",classpath:/static/";
                this.staticLocations = this.staticLocations.replace(",,", ",");
            }
    ​
            registry.addResourceHandler(new String[]{"/jimueport/*"}).addResourceLocations(new String[]{"file:" + this.upLoadPath + "//"}).addResourceLocations(this.staticLocations.split(","));
        }
    

如果项目是多数据源配置

  • 覆盖springboot auto配置jdbcTemplate的config

    /*
     * Copyright 2012-2019 the original author or authors.
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     *      https://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */package org.springframework.boot.autoconfigure.jdbc;
    ​
    import org.springframework.boot.autoconfigure.AutoConfigureAfter;
    import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
    import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
    import org.springframework.boot.context.properties.EnableConfigurationProperties;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.context.annotation.Import;
    import org.springframework.jdbc.core.JdbcTemplate;
    import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
    ​
    import javax.sql.DataSource;
    ​
    /**
     * {@link EnableAutoConfiguration Auto-configuration} for {@link JdbcTemplate} and
     * {@link NamedParameterJdbcTemplate}.
     *
     * @author Dave Syer
     * @author Phillip Webb
     * @author Stephane Nicoll
     * @author Kazuki Shimizu
     * @since 1.4.0
     */
    @Configuration(proxyBeanMethods = false)
    @ConditionalOnClass({ DataSource.class, JdbcTemplate.class })
    //@ConditionalOnSingleCandidate(DataSource.class)
    @AutoConfigureAfter(DataSourceAutoConfiguration.class)
    @EnableConfigurationProperties(JdbcProperties.class)
    @Import({ JdbcTemplateConfiguration.class, NamedParameterJdbcTemplateConfiguration.class })
    public class JdbcTemplateAutoConfiguration {
    ​
        public  JdbcTemplateAutoConfiguration(){
            System.out.println("覆盖jdbcTemplate配置");
        }
    ​
    }
    ​
    

报表设计->新建报表报错

  • 没有任务错误提示

  • 经过debug发现,是SnowflakeIdWorker依赖apache 的commons-lang3对应版本不兼容,目前配置3.10

                <properties>
                    <commons-lang3.version>3.10</commons-lang3.version>
                </properties>
                
                <dependency>
                    <groupId>org.apache.commons</groupId>
                    <artifactId>commons-lang3</artifactId>
                    <version>${commons-lang3.version}</version>
                </dependency>
    

扩展springmvc知识点

  • WebMvcConfigurer 可以实现多个
  • 底层webjar的是WebMvcAutoConfiguration里头嵌套的类WebMvcAutoConfigurationAdapter完成
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//package org.jeecg.modules.jmreport.config;
​
import org.jeecg.modules.jmreport.common.interceptor.JimuReportInterceptor;
import org.jeecg.modules.jmreport.common.util.oConvertUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
​
@Configuration("jimuReportConfiguration")
@PropertySource({"classpath:config/default-config.properties"})
public class JimuReportConfiguration implements InitializingBean, WebMvcConfigurer {
    private static final Logger log = LoggerFactory.getLogger(JimuReportConfiguration.class);
    @Value("${jeecg.path.upload}")
    private String upLoadPath;
    @Value("${spring.resource.static-locations}")
    private String staticLocations;
​
    public JimuReportConfiguration() {
    }
​
    @Bean
    public JimuReportInterceptor jimuReportInterceptor() {
        return new JimuReportInterceptor();
    }
​
    public void addInterceptors(InterceptorRegistry registry) {
        String[] var2 = new String[]{"/*.js", "/*.css", "/*.svg", "/*.pdf", "/*.jpg", "/*.png", "/*.ico", "/*.html", "/html/**", "/js/**", "/css/**", "/images/**"};
        registry.addInterceptor(this.jimuReportInterceptor()).excludePathPatterns(var2).addPathPatterns(new String[]{"/jmreport/**"});
    }
​
    @Bean
    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
        PropertySourcesPlaceholderConfigurer var0 = new PropertySourcesPlaceholderConfigurer();
        var0.setIgnoreUnresolvablePlaceholders(true);
        return var0;
    }
​
    public void afterPropertiesSet() throws Exception {
        log.info(" --- Init JimuReport Config --- ");
    }
​
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        if (oConvertUtils.isEmpty(this.staticLocations)) {
            this.staticLocations = "classpath:/static/";
        } else if (oConvertUtils.isNotEmpty(this.staticLocations) && this.staticLocations.indexOf("classpath:/static/") == -1) {
            this.staticLocations = this.staticLocations + ",classpath:/static/";
            this.staticLocations = this.staticLocations.replace(",,", ",");
        }
​
        registry.addResourceHandler(new String[]{"/jimueport/*"}).addResourceLocations(new String[]{"file:" + this.upLoadPath + "//"}).addResourceLocations(this.staticLocations.split(","));
    }
}
​

\