2

次の例外が発生しました。

org.springframework.beans.factory.NoSuchBeanDefinitionException: 依存関係のタイプ [pers.panxin.springboot.demo.mapper.UserMapper] の適格な Bean が見つかりません: この依存関係のオートワイヤー候補として適格な少なくとも 1 つの Bean が必要です。依存関係アノテーション: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

コントローラー:

@Controller
public class HelloController {

    @Autowired
    private UserService userService;

    @RequestMapping("/userList")
    @ResponseBody
    public String getAllUser(){
        return "userList : "+userService.getAllUser().toString();//+list.toString();
    }

}

サービス:

public interface UserService {

    public String getString();

    public List<User> getAllUser();

}

サービス実装:

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public String getString() {
        return "something else ... ";
    }

    @Override
    public List<User> getAllUser() {
        return userMapper.getAllUser();
    }
}

マッパー インターフェイス:

@Service
public interface UserMapper {

    /**
     * @return
     */
    public List<User> getAllUser();

}

アプリケーションのメイン クラス

@ComponentScan
@EnableAutoConfiguration
@SpringBootApplication
public class ApplicationStarter {

    public static void main(String[] args) {
        SpringApplication.run(ApplicationStarter.class, args);
    }

}

例外がどのように発生したか、またはコードで何か問題が発生しましたか?

4

3 に答える 3

0

1. mybatis-springライブラリを使用しているかどうかわかりません。MyBatis を Spring と統合しようとしている場合は、それを使用する必要があります。したがって、依存関係として持っていることを確認してください。

2. 依存関係として mybatis-spring がある場合は、この注釈を構成クラスに追加するだけです。

@MapperScan("package.where.mappers.are.located")

これは、mybatis-spring が MyBatis マッパーを個別にスキャンするためです。@Serviceまた、この別の mybatis-spring スキャンの場合、マッパーから注釈を削除する必要があります。

編集:

@Persia が指摘したように、mybatis-spring-boot-starterライブラリを使用して、mybatis-spring 依存関係を Spring Boot プロジェクトにプルできます。

于 2016-01-17T15:04:56.663 に答える