findByIdの競合?? Spring Boot Maven installエラー
Spring Boot入門という書籍のとおりコードを打っているのですが、エラーになり、どうすればいいかわからず困っています。どうかお助けください。
↓ファイルのエラー
package com.kuwa.springboot.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.kuwa.springboot.MyData;
@Repository
public interface MyDataRepository extends JpaRepository<MyData, Long> {
public MyData findById(Long name);
}
上記の「public MyData findById(Long name);」のMyDataに対して以下のエラー
”この行に複数マーカーがあります
- 戻りの型は CrudRepository.findById(Long) と互換性がありません
- Parameter type (Long) does not match domain class property definition (long).
- org.springframework.data.repository.CrudRepository.findById
を実装します”
↓Maven Install時のエラー
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MyBootApp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ MyBootApp ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 5 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ MyBootApp ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to C:\Users\yoshi\Documents\workspace-sts-3.9.2.RELEASE\MyBootApp\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/yoshi/Documents/workspace-sts-3.9.2.RELEASE/MyBootApp/src/main/java/com/kuwa/springboot/repositories/MyDataRepository.java:[12,23] com.kuwa.springboot.repositories.MyDataRepositoryのfindById(java.lang.Long)はorg.springframework.data.repository.CrudRepositoryのfindById(ID)と競合します
戻り値の型com.kuwa.springboot.MyDataはjava.util.Optional<com.kuwa.springboot.MyData>と互換性がありません
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.430 s
[INFO] Finished at: 2018-07-22T23:44:37+09:00
[INFO] Final Memory: 29M/211M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project MyBootApp: Compilation failure
[ERROR] /C:/Users/yoshi/Documents/workspace-sts-3.9.2.RELEASE/MyBootApp/src/main/java/com/kuwa/springboot/repositories/MyDataRepository.java:[12,23] com.kuwa.springboot.repositories.MyDataRepositoryのfindById(java.lang.Long)はorg.springframework.data.repository.CrudRepositoryのfindById(ID)と競合します
[ERROR] 戻り値の型com.kuwa.springboot.MyDataはjava.util.Optional<com.kuwa.springboot.MyData>と互換性がありません
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException