
親パッケージ、子モジュール☓2の構成でプロジェクトを作っています。
ディレクトリ構成は以下になります。
Package ←親プロジェクト
├── admin ←子モジュール
│ ├── pom.xml
│ └── src
│ └── main
│ └── java
│ └── admin
│ ├── AdminApplication.java
│ ├── WebSecurityConfig.java
│ ├── app
│ │ └── MainController.java
│ ├── component
│ └── domain
│ ├── model
│ ├── repository
│ └── service
├── web ←子モジュール
│ ├── pom.xml
│ ├── src
│ ├── main
│ ├── java
│ └── web
│ ├── WebApplication.java
│ ├── WebSecurityConfig.java
│ ├── app
│ │ └── WebMainController.java
│ └── service
※親パッケージを作ったのは、2つのプロジェクトで
DBが共通のため、子モジュールのwebでは、admin.domain以下を使いたかったためです。
Webモジュールの
WebApplication.java
Java
1package web; 2 3import org.springframework.boot.SpringApplication; 4import org.springframework.boot.autoconfigure.SpringBootApplication; 5 6@SpringBootApplication(scanBasePackages = {"web", "admin.domain"}) 7public class WebApplication { 8 9 public static void main(String[] args) { 10 SpringApplication.run(WebApplication.class, args); 11 12 } 13 14}
eclipseでwebモジュールを起動しようとすると、
以下エラーが出て起動できませんでした。
txt
1org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'admin.domain.repository.customer.CustomerRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 2 at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1493) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] 3 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] 4 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] 5 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] 6 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] 7 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.13.RELEASE.jar:4.3.13.RELEASE] 8 9.... 略 10 11 2018-01-08 12:19:26.610 ERROR 17257 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter : 12 13 *************************** 14 APPLICATION FAILED TO START 15 *************************** 16 17 Description: 18 19 Field customerRepository in web.domain.service.customer.AuthCustomerDetailsService required a bean of type 'admin.domain.repository.customer.CustomerRepository' that could not be found. 20 21 22 Action: 23 24 Consider defining a bean of type 'admin.domain.repository.customer.CustomerRepository' in your configuration. 25
子モジュールWebのAuthCustomerDetailsService.java
Java
1 package web.domain.service.customer; 2 3 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.security.core.userdetails.UserDetails; 5 import org.springframework.security.core.userdetails.UserDetailsService; 6 import org.springframework.security.core.userdetails.UsernameNotFoundException; 7 import org.springframework.stereotype.Component; 8 9 import admin.domain.model.PtCustomer; 10 import admin.domain.repository.customer.CustomerRepository; 11 12 13 @Component 14 public class AuthCustomerDetailsService implements UserDetailsService { 15 16 @Autowired 17 CustomerRepository customerRepository; 18 19 @Override 20 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 21 22 PtCustomer customer = customerRepository.findByCode(username); 23 if(customer == null){ 24 throw new UsernameNotFoundException(username + " is not found."); 25 } 26 27 return new AuthCustomerDetails(customer); 28 } 29 30 }

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/09 00:31
2018/01/09 00:33
2018/01/09 00:37