求助大佬们 idea 本地正常 发布平台报错

282 天前
 kestrelBright

idea 本地运行打包都正常,但发布平台运行不起来

多数据源

@MapperScan(basePackages = {"com.kestrel.saas.mapper"},
        sqlSessionFactoryRef = "sqlSessionFactory")
        
@MapperScan(basePackages = "com.kestrel.saas.mapper.collect", sqlSessionFactoryRef = "collectSqlSessionFactory")

yml

spring:
  application:
    name: iroq-pro
  profiles:
    active: dev
mybatis-plus:
  mapper-locations: classpath*:mappers/*.xml,classpath*:collect-mappers/*.xml

pom.xml 依赖

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.1.1</version>
        </dependency>
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.9.1</version>
        </dependency>
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>3.4.0</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>easyexcel</artifactId>
            <version>2.2.8</version>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-core</artifactId>
            <version>3.3.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-extension</artifactId>
            <version>3.3.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.3.2</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

发布平台错误 log

08:00 at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:439)
08:00 at org.springframework.boot.SpringApplication.run(SpringApplication.java:339)
08:00 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1340)
08:00 at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329)
08:00 at com.kestrel.App.main(App.java:37)
08:00 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
08:00 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
08:00 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
08:00 at java.lang.reflect.Method.invoke(Method.java:498)
08:00 at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
08:00 at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
08:00 at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
08:00 at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
08:00 Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'SqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'URL [jar:file:/opt/app.jar!/BOOT-INF/classes!/collect-mappers/QuerydetailMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'URL [jar:file:/opt/app.jar!/BOOT-INF/classes!/collect-mappers/QuerydetailMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.kestrel.saas.mapper.collect.QuerydetailMapper.QuerydetailMap
08:00 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
08:00 at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
08:00 ... 28 common frames omitted
08:00 Caused by: org.springframework.core.NestedIOException: Failed to parse mapping resource: 'URL [jar:file:/opt/app.jar!/BOOT-INF/classes!/collect-mappers/QuerydetailMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'URL [jar:file:/opt/app.jar!/BOOT-INF/classes!/collect-mappers/QuerydetailMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.kestrel.saas.mapper.collect.QuerydetailMapper.QuerydetailMap
08:00 at com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean.buildSqlSessionFactory(MybatisSqlSessionFactoryBean.java:593)
08:00 at com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean.afterPropertiesSet(MybatisSqlSessionFactoryBean.java:429)
08:00 at com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean.getObject(MybatisSqlSessionFactoryBean.java:626)
08:00 at com.kestrel.saas.config.CollectDataSourceConfig.SqlSessionFactory(CollectDataSourceConfig.java:47)
08:00 at com.kestrel.saas.config.CollectDataSourceConfig$$EnhancerBySpringCGLIB$$691472a0.CGLIB$SqlSessionFactory$1(<generated>)
08:00 at com.kestrel.saas.config.CollectDataSourceConfig$$EnhancerBySpringCGLIB$$691472a0$$FastClassBySpringCGLIB$$15a8d1fe.invoke(<generated>)
08:00 at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
08:00 at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
08:00 at com.kestrel.saas.config.CollectDataSourceConfig$$EnhancerBySpringCGLIB$$691472a0.SqlSessionFactory(<generated>)
08:00 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
08:00 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
08:00 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
08:00 at java.lang.reflect.Method.invoke(Method.java:498)
08:00 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
08:00 ... 29 common frames omitted
08:00 Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'URL [jar:file:/opt/app.jar!/BOOT-INF/classes!/collect-mappers/QuerydetailMapper.xml]'. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.kestrel.saas.mapper.collect.QuerydetailMapper.QuerydetailMap
08:00 at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:122)
08:00 at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:94)
08:00 at com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean.buildSqlSessionFactory(MybatisSqlSessionFactoryBean.java:591)
08:00 ... 42 common frames omitted
08:00 Caused by: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.kestrel.saas.mapper.collect.QuerydetailMapper.QuerydetailMap
08:00 at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:947)
08:00 at org.apache.ibatis.session.Configuration$StrictMap.put(Configuration.java:903)
08:00 at org.apache.ibatis.session.Configuration.addResultMap(Configuration.java:660)
08:00 at org.apache.ibatis.builder.MapperBuilderAssistant.addResultMap(MapperBuilderAssistant.java:209)
08:00 at org.apache.ibatis.builder.ResultMapResolver.resolve(ResultMapResolver.java:47)
08:00 at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:288)
08:00 at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElement(XMLMapperBuilder.java:253)
08:00 at org.apache.ibatis.builder.xml.XMLMapperBuilder.resultMapElements(XMLMapperBuilder.java:245)
08:00 at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:118)
08:00 ... 44 common frames omitted
08:00

QuerydetailMapper.xml 文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.kestrel.saas.mapper.collect.QuerydetailMapper">
    <sql id="Base_Column_List">
        identify,
        identify_time,
        create_time,
        id,
        sourcesQuery,
        queryIp,
        queryTime,
        productPc
    </sql>
    <resultMap type="com.kestrel.saas.entity.Querydetail" id="QuerydetailMap">
        <result property="identify" column="identify" jdbcType="VARCHAR"/>
        <result property="identifyTime" column="identify_time" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="VARCHAR"/>
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="sourcesquery" column="sourcesQuery" jdbcType="VARCHAR"/>
        <result property="queryip" column="queryIp" jdbcType="VARCHAR"/>
        <result property="querytime" column="queryTime" jdbcType="VARCHAR"/>
        <result property="productpc" column="productPc" jdbcType="VARCHAR"/>
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into IrQuerydetail(identify, identify_time, create_time, id, sourcesQuery, queryIp, queryTime, productPc)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.identify}, #{entity.identifyTime}, #{entity.createTime}, #{entity.sourcesquery}, #{entity.queryip}, #{entity.querytime}, #{entity.productpc})
        </foreach>
    </insert>
    <!-- 批量插入或按主键更新 -->
    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into IrQuerydetail(identify, identify_time, create_time, sourcesQuery, queryIp, queryTime, productPc)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.identify}, #{entity.identifyTime}, #{entity.createTime}, #{entity.sourcesquery}, #{entity.queryip}, #{entity.querytime}, #{entity.productpc})
        </foreach>
        on duplicate key update
identify = if(values(identify)  is not null,values(identify) ,identify), identify_time = if(values(identify_time)  is not null,values(identify_time) ,identify_time), create_time = if(values(create_time)  is not null,values(create_time) ,create_time), sourcesQuery = if(values(sourcesQuery)  is not null,values(sourcesQuery) ,sourcesQuery), queryIp = if(values(queryIp)  is not null,values(queryIp) ,queryIp), queryTime = if(values(queryTime)  is not null,values(queryTime) ,queryTime), productPc = if(values(productPc)  is not null,values(productPc) ,productPc)    </insert>

    <select id="countByQuerytime" resultType="java.lang.Integer">
        select count(1)
        from IrQuerydetail
        <where>
            <if test="querytime != null and querytime != ''">
                and queryTime>=#{querytime,jdbcType=VARCHAR}
            </if>
        </where>
    </select>

    <select id="latestList" resultType="com.kestrel.saas.dto.IrQueryStatistics.QueryStatisticsMapDto">
        select qsd.queryTime,qsd.productPc,qs.productName,qs.productSort from IrQuerydetail qsd left join IrQueryStatistics qs on qsd.productPc=qs.productPc order by queryTime desc limit #{pageSize};
    </select>

    <select id="groupByMonth" resultType="java.util.Map">
        select DATE_FORMAT(FROM_UNIXTIME(queryTime / 1000), '%Y%m') as months,count(1) as count from  IrQuerydetail GROUP BY months;
    </select>

</mapper>

查了全项目 resultType id 没重复,全项目 select id 也没重复,全项目 xml 文件没有重复多余

1191 次点击
所在节点    程序员
11 条回复
pannanxu
282 天前
我看 <resultMap type="com.kestrel.saas.entity.Querydetail" id="QuerydetailMap">
没用上,就删掉呗
kestrelBright
282 天前
@pannanxu 是的 删掉可以,想搞明白是啥引起的,总不能一直不用 resultMap
pangdundun996
282 天前
dao 层 mapper 是单独的 module 吗?如果是的话可能本地引用的不是最新的 module
kestrelBright
282 天前
@pangdundun996 不太明白您的意思,mapper 是单独包 com.kestrel.saas.mapper 和 com.kestrel.saas.mapper.collect
我刚本地 maven clean 了 重新运行也正常
JYii
282 天前
如果确定是同一个分支的话,应该考虑不同的变量 jdk ,maven 依赖库之类的吧
kestrelBright
282 天前
@JYii 公司的 DevOps 平台
shanghai1943
282 天前
对比一下本地以及平台打包出来的包都有哪些,版本都是什么,确认一下是不是版本不同导致运行结果不同。
gejun123456
282 天前
QuerydetailMap 改个名字试试,有可能用了啥 mybatis interceptor 注入了这种名字的 resultMap,改成 MyResultMap 看看
kestrelBright
282 天前
...问了公司的 原来发布 pom 要 exclude 掉 mapper 的 xml 文件。。。

谢各位大佬
kestrelBright
282 天前
@gejun123456 已经可以了,大佬回复 不胜惶恐
pannanxu
282 天前
@kestrelBright #2 我从干开发到现在就没用过 resultMap 。都用 mbp 了还搞那么复杂。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/976834

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX