Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.companyname.enterpriseteam.demo.anonymizer.DAnonymizer' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
Here is a mock but logically accurate representation of the code
Config Package
…
import org.companyname.enterpriseteam.demo.anonymizer.DAnonymizer;
import org.companyname.entuserfilter.externals.adminusersearch.AdminSearchUserRecordsAnonymizer;
…
@Configuration
public class AdminUserSearchAnonymizationConfiguration {
@Bean
public AdminSearchUserRecordsAnonymizer
adminSearchUserRecordsAnonymizer(final DAnonymizer dAnonymizer) {
return new adminSearchUserRecordsAnonymizerImpl(dAnonymizer);
}
}
New interface I created in a different package
…
Some imports
…
public interface AdminSearchUserRecordsAnonymizer {
List<StoredUserRecord> anonymizeAdminSearchUserRecordsIfNeeded(
final List<StoredUserRecord> storedUserRecords,
final String orgId,
@Nullable final Long requestUserId);
}
The interface's implementation
…
Some imports
…
public class AdminSearchUserRecordsAnonymizerImpl
implements AdminSearchUserRecordsAnonymizer {
private final DAnonymizer dAnonymizer;
public AdminSearchUserRecordsAnonymizerImpl(final DAnonymizer dAnonymizer) {
this.dAnonymizer = dAnonymizer;
}
@Override
public List<StoredUserRecord> anonymizeAdminSearchUserRecordsIfNeeded(
final List<StoredUserRecord> storedUserRecords,
final String orgId,
@Nullable final Long requestUserId) {
if (!DConstants.COMPANY_ORG_ID.equals(orgId) || requestUserId == null) {
// System.out.println("NO ANONYMIZATION" + storedUserRecords);
return storedUserRecords;
}
// System.out.println("ANONYMIZATION TO BE DONE ON USER RECORDS LIST" + storedUserRecords);
return storedUserRecords.stream()
.map(entry -> anonymizeUserRecordIfNeeded(entry, orgId, requestUserId))
.collect(Collectors.toList());
}
private StoredUserRecord anonymizeUserRecordIfNeeded(
final StoredUserRecord storedUserRecord, final String orgId, final Long requestUserId) {
final var anonymizedStoredUserRecord =
dAnonymizer.getAnonymizedUserInfoForOrg(
orgId, storedUserRecord.userId().get(), requestUserId);
return anonymizedStoredUserRecord
.map(
anon ->
new StoredUserRecord(
storedUserRecord.userId(),
anon.email(),
storedUserRecord.externalId(),
anon.name(),
.orElse(storedUserRecord);
}
}
Constructor of class where dependency injection is performed
…
Some imports
…
public class AdminViewElasticSearchManager implements AdminViewManager {
private final someObject1;
private final someObject2;
private final someObject3;
private final someObject4;
private final AdminSearchUserRecordsAnonymizer
adminSearchUserRecordsAnonymizer;
public AdminViewElasticSearchManager(
someClass1 someObject1,
someClass2 someObject2,
someClass3 someObject3,
someClass4 someObject4,
AdminSearchUserRecordsAnonymizer
adminSearchUserRecordsAnonymizer
) {
this.elasticSearchReader = elasticSearchReader;
this.someObject1 = someObject1;
this.someObject2 = someObject2;
this.someObject3 = someObject3;
this.someObject4 = someObject4;
this.adminSearchUserRecordsAnonymizer =
adminSearchUserRecordsAnonymizer;
}
Me using my new implementation's method somewhere in that same class above
@Override
public UserRecordsWithPagination searchWithFilterParams(filterParams, pageRequest, requestUser) {
…
Some code
…
storedUserRecords =
this.adminSearchUserRecordsAnonymizer.anonymizeAdminSearchUserRecordsIfNeeded(
storedUserRecords, filterParams.orgId, requestUser);
…
More code
…
}
Many tests are failing due to dependency injection issues and because of it, I can't test properly. This particular test is also not asserting like it should meaning my new class isn't returning the proper list to its caller. I wonder if its related to dependencies not being injected properly?
…
var filterParams =
FilterParams.newBuilder()
.setOrganizationId(UserRecordFixtures.MEMBER_USER_RECORD.organizationId())
.setSearchNameOrEmails(List.of("johndoe"))
.build();
var pageRequest =
PageRequest.newBuilder()
.setStart(Int64Value.of(0))
.setLimit(Int64Value.of(1))
.build();
var result = this.manager.queryByFilterParams(filterParams, pageRequest, null);
System.out.println("THIS IS MY RESULT: " + result);
Assertions.assertEquals(1, result.userRecords().size());
…
Define bean of DAnonymizer
in config class like below
@Configuration
public class DAnonymizerConfig {
@Bean
public DAnonymizer dAnonymizer() {
return new DAnonymizer();//considering DAnonymizer has default constructor
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.