spring bootでspring boot securityを使ったログイン認証を実装している途中なのですが、
起動時に「Description:
Field userRepository in co.jp.yuki.koike.sample.domain.service.user.UserDetailsServiceImpl required a bean of type 'co.jp.yuki.koike.sample.domain.service.user.UserRepository' that could not be found.
」
と表示され、起動できません。
恐らく、
sample\src\main\java\co\jp\yuki\koike\sample\domain\service\user\UserDetailsServiceImpl.java
か、
sample\src\main\java\co\jp\yuki\koike\sample\domain\service\user\UserRepository.java
に原因があると思います。
githubにあげたものを見てご指摘いただけないでしょうか?
githubにあげたソースコード
↑repositoryを削除致しました。
■ 起動時のログ
. ____ _ __ _ _ /\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ / _` | \ \ \ \ \/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v2.0.1.RELEASE) 2018-06-20 09:00:37.955 INFO 8960 --- [ main] co.jp.yuki.koike.sample.SampleApplication : Starting SampleApplication on DESKTOP-BD2CRPU with PID 8960 (C:\Users\nec\git\sample\target\classes started by nec in C:\Users\nec\git\sample) 2018-06-20 09:00:37.970 INFO 8960 --- [ main] co.jp.yuki.koikr.sample.SampleApplication : No active profile set, falling back to default profiles: default 2018-06-20 09:00:38.601 INFO 8960 --- [ main] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@61230f6a: startup date [Wed Jun 20 09:00:38 JST 2018]; root of context hierarchy 2018-06-20 09:00:45.514 INFO 8960 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2018-06-20 09:00:45.622 INFO 8960 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2018-06-20 09:00:45.622 INFO 8960 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.29 2018-06-20 09:00:45.646 INFO 8960 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\pleiades-4.7.1-ultimate-win-64bit-jre_20171019\pleiades\eclipse\jre\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/pleiades-4.7.1-ultimate-win-64bit-jre_20171019/pleiades/eclipse/jre/bin/../jre/bin/server;C:/pleiades-4.7.1-ultimate-win-64bit-jre_20171019/pleiades/eclipse/jre/bin/../jre/bin;C:/pleiades-4.7.1-ultimate-win-64bit-jre_20171019/pleiades/eclipse/jre/bin/../jre/lib/amd64;C:\app\nec\product\12.2.0\dbhome_1\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Java\jdk1.8.0_151\bin;C:\HashiCorp\Vagrant\bin;C:\Program Files\PuTTY\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\TortoiseGit\bin;C:\Program Files (x86)\Nodist\bin;C:\Users\nec\AppData\Local\Microsoft\WindowsApps;;C:\Users\nec\AppData\Local\Programs\Fiddler;C:\pleiades-4.7.1-ultimate-win-64bit-jre_20171019\pleiades\eclipse;;.] 2018-06-20 09:00:46.940 INFO 8960 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2018-06-20 09:00:46.940 INFO 8960 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 8354 ms 2018-06-20 09:00:47.308 INFO 8960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*] 2018-06-20 09:00:47.308 INFO 8960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*] 2018-06-20 09:00:47.308 INFO 8960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*] 2018-06-20 09:00:47.308 INFO 8960 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*] 2018-06-20 09:00:47.308 INFO 8960 --- [ost-startStop-1] .s.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*] 2018-06-20 09:00:47.308 INFO 8960 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/] 2018-06-20 09:00:47.862 WARN 8960 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsServiceImpl': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'co.jp.g.n.sample.domain.service.user.UserRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 2018-06-20 09:00:47.878 INFO 8960 --- [ main] o.apache.catalina.core.StandardService : Stopping service [Tomcat] 2018-06-20 09:00:48.445 INFO 8960 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-06-20 09:00:48.810 ERROR 8960 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Field userRepository in co.jp.yuki.koikr.sample.domain.service.user.UserDetailsServiceImpl required a bean of type 'co.jp.yuki.koikr.sample.domain.service.user.UserRepository' that could not be found. Action: Consider defining a bean of type 'co.jp.yuki.koike.sample.domain.service.user.UserRepository' in your configuration.
■ UserDetailsServiceImpl.java
java
1package co.jp.yuki.koike.sample.domain.service.user; 2 3import java.util.Optional; 4 5import org.springframework.beans.factory.annotation.Autowired; 6import org.springframework.security.core.userdetails.UserDetails; 7import org.springframework.security.core.userdetails.UserDetailsService; 8import org.springframework.security.core.userdetails.UsernameNotFoundException; 9import org.springframework.stereotype.Service; 10 11import co.jp.yuki.koike.sample.domain.model.User; 12 13@Service 14public class UserDetailsServiceImpl implements UserDetailsService { 15 16 @Autowired 17 UserRepository userRepository; 18 19 20 @Override 21 public UserDetails loadUserByUsername(String username) 22 throws UsernameNotFoundException { 23 User user = Optional.ofNullable(userRepository.findOne(username)) 24 .orElseThrow(() -> new UsernameNotFoundException(username + " is not found.")); 25 return new UserDetailsImpl(user); 26 } 27} 28
■ UserRepository.java
java
1package co.jp.yuki.koike.sample.domain.service.user; 2 3import org.springframework.data.jpa.repository.JpaRepository; 4 5import co.jp.yuki.koike.sample.domain.model.User; 6 7public interface UserRepository extends JpaRepository<User, String> { 8 9 User findOne(String username); 10} 11


回答1件
あなたの回答
tips
プレビュー