IDEA解决Maven项目编译后classes文件中没有.xml问题

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): Mapper接口中的某个方法

这个原因是因为maven 编译时并没有把 .xml 文件放到 target文件夹下的classes文件夹中,

解决步骤:

1、在pom添加如下代码

<build>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>

 

2、1.点击Maven Projects  ,2.选择mapper文件所在的项目 3.将项目中的target文件夹clean掉。

        

3、点击需要重新生成 classes 文件夹项目,鼠标右键选项中点击maven处下的 Reimport 选项。然后将项目 Build 下,看下classes 是否将mapper.xml 文件加载进去。

  • 10
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
IDEA 开发环境,使用 Maven 项目时,可以使用 profile 来指定不同的环境。通常情况下,我们会为开发、测试和部署环境创建不同的 profile。具体步骤如下: 1. 在 pom.xml 文件,添加 profile 标签。 ``` <profiles> <profile> <id>dev</id> <properties> <env>dev</env> </properties> </profile> <profile> <id>test</id> <properties> <env>test</env> </properties> </profile> <profile> <id>prod</id> <properties> <env>prod</env> </properties> </profile> </profiles> ``` 这里我们创建了三个 profile,分别对应着 dev、test 和 prod 环境。 2. 在 pom.xml 文件,添加 build 标签,并在其引用 profile。 ``` <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> <executions> <execution> <id>default-copy-resources</id> <phase>process-resources</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/classes</outputDirectory> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> </resource> </resources> </configuration> </execution> </executions> </plugin> </plugins> </build> ``` 这里我们使用 Maven 插件 maven-resources-plugin,将 src/main/resources 目录的资源文件复制到 target/classes 目录,并在复制的过程进行过滤,替换其的占位符。 3. 在 resources 目录,创建三个文件夹 dev、test 和 prod,并在其创建一个名为 application.properties文件。 ``` src/main/resources/ ├── dev │ └── application.properties ├── prod │ └── application.properties └── test └── application.properties ``` 这里我们为每个环境创建了一个 application.properties 文件,用于存放该环境的配置信息。 4. 在 application.properties 文件,添加一些配置信息。 ``` server.port=8080 spring.datasource.url=jdbc:mysql://localhost:3306/mydb spring.datasource.username=root spring.datasource.password=root ``` 这里我们添加了一些常用的配置信息。 5. 在 IDEA 开发环境,选择 Edit Configurations,在其添加一个 Maven 配置。 6. 在 Command line 输入以下命令: ``` clean install -Pdev ``` 这里的 -P 参数表示指定 profile,这里我们指定了 dev 环境。 7. 点击 OK,保存配置。 现在,我们可以在 dev 环境运行项目了。如果需要在其他环境运行项目,只需要更改 Command line 的 profile 参数即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值