구성 [Spring-Boot]에서 '패키지' 유형의 빈을 정의하는 것을 검토하십시오.
다음의 에러가 표시됩니다.
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method setApplicant in webService.controller.RequestController required a bean of type 'com.service.applicant.Applicant' that could not be found.
Action:
Consider defining a bean of type 'com.service.applicant.Applicant' in your configuration.
이 에러는 지금까지 본 적이 없습니다만, @Autowire가 동작하지 않는 것은 이상합니다.프로젝트 구조는 다음과 같습니다.
신청자 인터페이스
public interface Applicant {
TApplicant findBySSN(String ssn) throws ServletException;
void deleteByssn(String ssn) throws ServletException;
void createApplicant(TApplicant tApplicant) throws ServletException;
void updateApplicant(TApplicant tApplicant) throws ServletException;
List<TApplicant> getAllApplicants() throws ServletException;
}
신청자 임플
@Service
@Transactional
public class ApplicantImpl implements Applicant {
private static Log log = LogFactory.getLog(ApplicantImpl.class);
private TApplicantRepository applicantRepo;
@Override
public List<TApplicant> getAllApplicants() throws ServletException {
List<TApplicant> applicantList = applicantRepo.findAll();
return applicantList;
}
}
할 수 만, 이 경우, 「Autowire Applicant」로하지 않습니다.@RestController:
@RestController
public class RequestController extends LoggingAware {
private Applicant applicant;
@Autowired
public void setApplicant(Applicant applicant){
this.applicant = applicant;
}
@RequestMapping(value="/", method = RequestMethod.GET)
public String helloWorld() {
try {
List<TApplicant> applicantList = applicant.getAllApplicants();
for (TApplicant tApplicant : applicantList){
System.out.println("Name: "+tApplicant.getIndivName()+" SSN "+tApplicant.getIndSsn());
}
return "home";
}
catch (ServletException e) {
e.printStackTrace();
}
return "error";
}
}
---------------------------------------------------------------------
나는 덧붙였다.
@SpringBootApplication
@ComponentScan("module-service")
public class WebServiceApplication extends SpringBootServletInitializer {
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(WebServiceApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(WebServiceApplication.class, args);
}
}
오류는 사라졌지만 아무 일도 일어나지 않았습니다. 제가 지만 with with with에 관한 때Applicant
RestController
를 추가하기 @ComponentScan()
수 .UI
, 나의 ,, 의를 의미합니다RestController
동작하고 있었는데, 지금은 건너뜁니다.Whitelabel Error Page
-------------------------------------------------------------
나는 그것이 불평하는 콩의 기본 패키지를 추가했다.에러 판독:
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method setApplicantRepo in com.service.applicant.ApplicantImpl required a bean of type 'com.delivery.service.request.repository.TApplicantRepository' that could not be found.
Action:
Consider defining a bean of type 'com.delivery.request.request.repository.TApplicantRepository' in your configuration.
는 ㅇㅇㅇㅇㅇㅇㅇㅇ다를 넣었습니다.@ComponentScan
@SpringBootApplication
@ComponentScan({"com.delivery.service","com.delivery.request"})
public class WebServiceApplication extends SpringBootServletInitializer {
@Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(WebServiceApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(WebServiceApplication.class, args);
}
}
-------------------------------------------------------------------------------------------------
추가:
@SpringBootApplication
@ComponentScan("com")
public class WebServiceApplication extends SpringBootServletInitializer {
도 제 있어요.ApplicantImpl
의 @Autowires
TApplicantRepository
그 안에.
프로젝트가 다른 모듈로 분해되었기 때문일 수 있습니다.
@SpringBootApplication
@ComponentScan({"com.delivery.request"})
@EntityScan("com.delivery.domain")
@EnableJpaRepositories("com.delivery.repository")
public class WebServiceApplication extends SpringBootServletInitializer {
★★★★★★★★…@Service
,@Repository
각 구현 클래스에 대한 주석을 표시합니다.
당신의 신청자 클래스는 스캔되지 않은 것 같습니다.으로는 root에서 하는 모든 패키지는 로, root에서 입니다.@SpringBootApplication
캔캔됩됩됩됩됩
라고 해 봅시다.main
"Web Application은 "Web Service Application"에.com.service.something
후, 모든 가 「이러한 컴포넌트」에com.service.something
" "이렇게 하면 됩니다.com.service.applicant
"는 스캔되지 않습니다.
"WebServiceApplication"이 루트 패키지에 속하고 다른 모든 구성 요소가 해당 루트 패키지의 일부가 되도록 패키지를 재구성할 수 있습니다. '먹다'를 넣을 도 있어요.@SpringBootApplication(scanBasePackages={"com.service.something","com.service.application"})
스프링 컨테이너에서 "모든" 구성 요소가 스캔되고 초기화되도록 합니다.
코멘트에 근거한 갱신
maven/gradle에 의해 관리되는 모듈이 여러 개 있는 경우 스캔할 패키지만 있으면 됩니다.spring에 "com.module1"을 스캔하도록 지시하고 루트 패키지 이름이 "com.module2"인 다른 모듈이 있으면 이러한 컴포넌트는 스캔되지 않습니다.스프링에 "com"을 스캔하도록 지시할 수도 있습니다.이 경우 "의 모든 컴포넌트가 스캔됩니다.com.module1.
및 " " " "com.module2.
기본적으로 클래스 어플리케이션이 "다른 패키지"에 포함되어 있을 때 발생합니다.예를 들어 다음과 같습니다.
com.server
- Applicacion.class (<--this class have @ComponentScan)
com.server.config
- MongoConfig.class
com.server.repository
- UserRepository
Application.class에서 이 문제를 해결합니다.
@SpringBootApplication
@ComponentScan ({"com.server", "com.server.config"})
@EnableMongoRepositories ("com.server.repository") // this fix the problem
다른 방법으로는 모든 컨피규레이션클래스를 같은 패키지에 넣는 방법이 있습니다.
저 같은 경우에는 큰 실수를 했어요.@Service
이치노
고치기 위해 는 치치해 to를 넣었다.@Service
서비스 파일 구현에 대해 설명했고, 제게는 효과가 있었습니다.
콩이 @Autowired와 같은 패키지에 포함되어 있는 경우, 이러한 문제는 발생하지 않습니다.그러나 기본적으로는 다른 패키지에서 콩에 액세스할 수 없습니다.이 문제를 해결하려면 , 다음의 순서에 따릅니다.
- 기본 클래스에서 다음을 가져옵니다.
import org.springframework.springframework.;컴포넌트 스캔; - 메인 클래스에 주석을 추가합니다.
@ComponentScan(basePackages = {"your.company.domain.package"})
public class SpringExampleApplication {
public static void main(String[] args) {
SpringApplication.run(SpringExampleApplication.class, args);
}
}
저는 Maven Multi-Module 프로젝트에서 Spring Boot 2와 관련된 익숙한 문제에 직면했습니다.이 문제는 서브 Maven 모듈의 패키지에 이름을 붙이는 것과 관련이 있습니다.
@Spring Boot Application은 @ComponentScan, @Enable과 같은 많은 컴포넌트를 캡슐화합니다.자동 구성, jpa-리포지토리, json-serialization 등입니다.@ComponentScan을 com에 배치합니다.******** 공간 패키지.패키지의 이 부분은 com입니다.********는 모든 모듈에 공통공간이어야 합니다.
수정의 경우:
- 모든 모듈 패키지의 이름을 변경해야 합니다.즉, 모든 Maven 모듈의 모든 패키지에 동일한 상위 부품을 포함해야 했습니다.예를 들어 - com 입니다.********* 공간
- 또한 이 패키지 - com으로 진입점을 이동해야 합니다.********* 공간
중요:
일반적인 bean 에러 메시지를 구글에 검색하여 가져온 사용자 중 실제로 Spring Boot 어플리케이션에 가짜 클라이언트를 추가하려고 하는 사용자용입니다.@FeignClient
클라이언트 인터페이스에 주석을 붙이면 위의 어떤 솔루션도 작동하지 않습니다.
하려면 , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,@EnableFeignClients
응용 프로그램
@SpringBootApplication
// ... (other pre-existing annotations) ...
@EnableFeignClients // <------- THE IMPORTANT ONE
public class Application {
노트: " " " : "@ComponentScan(...)
밑에@SpringBootApplication
용장성이며 IDE는 용장성이라고 플래그를 붙여야 합니다(IntelliJ IDEA는 적어도 그렇습니다).
이고 롬복 사용 할 수 .@RequiredArgsConstructor
★★★★★★★★★★★★★★★★★」@NonNull
일부 필드는 생성자에 삽입되지 않습니다.이것은 같은 에러가 발생할 수 있는 가능성 중 하나에 불과합니다.
매개 변수 0을(를) 찾을 수 없는 MissingBeanName 유형의 빈이 필요함
, 에 의해 되었습니다.「 」 「 」 「 」 「 」 「 」 「 」 「 」 「 」 「 」를 삭제한 후, 가 발생한 컨트롤러가 됩니다.@NonNull
프로그램이 정상적으로 시작되었습니다.
제 경우에는 이 두 가지 옵션이 효과가 있었습니다.
//@ComponentScan ({"myapp", "myapp.resources","myapp.services"})
또한 를 수용하는 패키지를 포함한다.Application.class
내 내「 「 」를 만 하면 .
@EnableAutoConfiguration
모든 봄콩을 자동으로 인식합니다.
수 것 요.@Repository
찾고, 자동으로 해당 스프링 프레임워크에 의해 작동된다.스프링 Framework에자동으로 활성화됩니다 의해.
어플리케이션에서 아래 주석을 추가하자 효과가 있었습니다.
@ComponentScan({"com.seic.deliveryautomation.mapper"})
다음 오류가 발생했습니다.
"의 컨스트럭터의 파라미터 1에는 찾을 수 없는 유형의 bean이 필요합니다.
Springboot 어플리케이션(application.java) 파일을 다른 패키지로 이동하면 문제가 해결되었습니다.컨트롤러 및 저장소와 분리하여 보관합니다.
온라인으로 답변을 구했지만 내 사례에 대한 적절한 해결책은 없는 것 같습니다.처음에는 모든 것이 다음과 같이 잘 작동합니다.
@Slf4j
@Service
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class GroupService {
private Repository repository;
private Service service;
}
그런 다음 맵을 추가하여 캐시하려고 하면 다음과 같이 됩니다.
@Slf4j
@Service
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class GroupService {
private Repository repository;
private Service service;
Map<String, String> testMap;
}
쾅!
Description:
Parameter 4 of constructor in *.GroupService required a bean of type 'java.lang.String' that could not be found.
Action:
Consider defining a bean of type 'java.lang.String' in your configuration.
나는 제거했습니다를 제거했다.@AllArgsConstructor(onConstructor = @__(@Autowired))
그리고 추가 추가하다@Autowired
각 각각에 대해서에repository
그리고 그리고.service
그 을 제외하고를 제외하고Map<String, String>
. 그냥 before.로 일한다.그냥 예전처럼 작동합니다.
@Slf4j
@Service
public class SecurityGroupService {
@Autowired
private Repository repository;
@Autowired
private Service service;
Map<String, String> testMap;
}
이게 도움이 됐으면 좋겠네요.
이 문제는 @Service 클래스가 abstract로 마크되어 있는 경우에 발생할 수 있습니다.
이 에러는, 예를 들면 spring을 사용하는 등, Import가 잘못되었기 때문에 표시됩니다.
import org.jvnet.hk2.annotations.Service;
하지만 난 필요했어:
import org.springframework.stereotype.Service;
@설정에 주석을 달면 오류가 해결됩니다.
두 개의 다른 클래스에서 실수로 같은 콩을 정의한 경우에도 이 오류가 발생합니다.저도 그랬어요.에러 메세지는 오해의 소지가 있었다.여분의 콩을 제거하자 문제가 해결되었습니다.
저도 같은 문제에 직면했어요.Mongo DB 저장소는 Spring 부팅에 의해 식별되었지만 Mongo 저장소를 확장하는 저장소 인터페이스용 Bean을 생성하지 않았습니다.
제 경우 maven pom의 spring + mango 버전 지정이 잘못되어 있었습니다.아티팩트의 그룹 ID를 변경했는데 모두 마법처럼 작동했어요.스프링 부츠가 모든 것을 처리하므로 주석이 필요하지 않습니다.
문제를 해결하는 동안 웹에서 해결책을 찾다가 이 문제가 실제로 프로젝트 구성과 관련된 것임을 깨달았습니다.이 문제에 직면한 사람은 먼저 프로젝트 설정을 확인하고 봄부터 디버깅을 활성화하여 장애에 대한 자세한 정보를 얻고 프로세스 중 정확히 어디에 있는지 주의 깊게 살펴야 합니다.d.
프로젝트 구조를 다음과 같이 구성하십시오.
모든 repo, 서비스, 패키지를 메인 패키지의 자 패키지에 넣습니다.
package com.leisure.moviemax; //Parent package
@SpringBootApplication
@PropertySource(value={"classpath:conf.properties"})
public class MoviemaxApplication implements CommandLineRunner {
package com.leisure.moviemax.repo; //child package
@Repository
public interface UsrRepository extends JpaRepository<UserEntity,String> {
이 오류 메시지는 주석으로 콩과 연관된 엔티티 클래스에 주석을 달지 못한 경우에도 표시됩니다.
내 나의ComponentScan
좋은데 이것이 정상적으로 동작했지만,이 메시지가 표시됩니다에 떠 일해.@repository
인터페이스:인터페이스:
@Repository
public interface ExpenseReportAuditRepository extends
PagingAndSortingRepository<ExpenseReportAudit, Integer> {
왜냐하면 나는 @ 엔티티에@ 엔티티 주석을 추가하는 데 실패했다못했기 때문에 추가하지 주석을.ExpenseReportAudit
@Entity // <--- Adding this fixed the issue.
public class ExpenseReportAudit {
.....
@SpringBootApplication
@MapperScan("com.developer.project.mapper")
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
클래스 의존관계가 봄까지 관리되고 있는 경우 POJO 클래스 내에 default/empty arg 컨스트럭터를 추가하는 것을 잊은 경우 이 문제가 발생할 수 있습니다.
제 실수는 다음을 포함시켰다는 것입니다.
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
다음 대신:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
누군가 도움이 될지도 몰라같은 문제, 같은 오류 메시지, 모든 게 똑같았어요.저는 다른 답변의 해결책을 시도했지만, 제가 사용하고 있는 콩의 이름이 실제로 자동배선된 것과 같다는 것을 알 때까지 도움이 되지 않았습니다.리팩터 중에 일어난 일이라 수업 이름을 바꾸어야 했고, 그 결과는 긍정적이었습니다.건배.
제 경우, 저희 프로젝트에는 컨피규레이션클래스가 있어서 이렇게 추가했습니다.
@Configuration
public class DependencyConfiguration {
@Bean
public ActivityService activityService(
@Value("${send.money.ms.activity.url}") final String activityHistoryUrl,
final HttpRestService httpRestService
) {
return new ActivityServiceImpl(activityHistoryUrl, httpRestService);
}
.......................
그리고 나서 마이크로 서비스가 정상적으로 시작되었습니다.
PS: 필요한 라이브러리가 올바르게 Import되어 Import된 외부 라이브러리에서 볼 수 있는데도 이 문제가 발생하였습니다.
서비스 클래스에 RestTemplate를 삽입해야 하는 경우가 있었습니다.단, RestTemplate는 서비스 클래스에서 픽업할 수 없습니다.메인 어플리케이션과 같은 패키지에 래퍼 클래스를 만들고 래퍼에 컴포넌트로 마크하여 서비스 클래스에서 이 컴포넌트를 자동 배선합니다.문제는 해결됐습니다.당신에게도 효과가 있기를 바랍니다.
제 말은, 당신이 RequestController 요청 Controller에 빈 @의 @ 빈 주석이 실종되고 있것 같습니다 없는 주석이 생각한다.
당신 파일의 빈 추가를 이 파일에 제 문제 Bean을 추가하면문제가 해결됩니다를 해결했다.
은 tutorialspoint tutorialspoint에서 때 되었습니다.
private Applicant applicant;
@Bean
public Applicant applicant() {
return new Applicant();
}
Spring Boot Data JPA Starter 의존관계를 추가하면 문제가 해결되었습니다.
메이븐
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>
그라들
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.2.6.RELEASE'
아니면 여기로 직접 가셔도 됩니다.
「 」를 사용하고 interface
「」를 확장할 수 .CrudRepository<Applicant,Long>
@Repository
석입니니다다
언급URL : https://stackoverflow.com/questions/40384056/consider-defining-a-bean-of-type-package-in-your-configuration-spring-boot
'programing' 카테고리의 다른 글
Vee-validate 3.0에서 URL을 검증하는 방법 (0) | 2022.07.02 |
---|---|
Nuxt.js 스토어, 다른 스토어에 디스패치액션 (0) | 2022.07.02 |
이거 보세요.$140입니다.set Timeout 푸시 (0) | 2022.07.02 |
vuex에서 getter의 특별한 용도는 무엇입니까? (0) | 2022.07.02 |
Vuex getter의 v-if (0) | 2022.07.01 |