@daiya7110

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

spring boot 環境でアプリ実行時にエラーが発生してしまいます。

spring boot 環境でアプリ実行時にエラーが発生してしまいます。
有識者の方ご教授をお願いいたします。

タイトルの通りですがspring boot 環境でアプリ実行時に以下のエラーが出てしまいます。

発生している問題・エラー

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
[2m2025-11-25T00:56:42.241+09:00[0;39m [31mERROR[0;39m [35m18948[0;39m [2m--- [todoapp] [           main] [0;39m[36mo.s.b.d.LoggingFailureAnalysisReporter  [0;39m [2m:[0;39m 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field todoMapper in com.todo.app.controller.TodoController required a bean of type 'com.todo.app.mapper.TodoMapper' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.todo.app.mapper.TodoMapper' in your configuration.

自分なりに調べ[pom.xml]に以下を追記しましたが状況は変わらず。。。。

追記したコード

<dependency>
	<groupId>org.mybatis.spring.boot</groupId>
	<artifactId>mybatis-spring-boot-starter</artifactId>
	<version>3.0.4</version>
</dependency>

以下追記

Mapper.java


package com.todo.app.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Mapper;

import com.todo.app.entity.Todo;

@Mapper
public interface TodoMapper {

	public List<Todo> selectAll();
}

MapperInterfaceがDIされてないてきなエラーということでしたがコードを確認してみたところ@Mapperアノテーションはしっかりついています、、

いろいろ調べていましたが猶更訳が分からなくなってしまいました。。

使用しているSpringのバージョンが「4.0.0」に対してMybatisのバージョンが低いのでしょうか、、

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

判断に追加で必要な情報ありましたら追記していきます。

0 likes

1Answer

2点対応が必要です。

1.バージョン問題
以下リンク内の「Creating new project via Spring Initializr」をクリックして、Spring Initializrを開きます。
SpringBootのバージョン、4.0.0には対応していないことが分かります(赤文字で表示されている)ので、バージョン調整が必要です。

2.エラー文に記載通りの対応
1の対応完了後にも、以下エラーが発生する場合は、対応してください。

> Action:

Consider defining a bean of type 'com.todo.app.mapper.TodoMapper' in your configuration.
0Like

Your answer might help someone💌