Хочу показать информацию из одного микросервиса в другойJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Хочу показать информацию из одного микросервиса в другой

Сообщение Anonymous »

У меня есть 3 службы: «Пользователь», «Продукт» и «Налог».
Все они содержат идентификаторы пользователя, продукта и налога. каждый из них уникален и создан только в своем собственном сервисе.
Теперь я пытаюсь отобразить данные для всех пользователей, где у них может быть несколько объектов недвижимости, но с каждым объектом недвижимости связан только один налог. . Поэтому я создал все в соответствии с ним.
Изображение

мои объекты
ПОЛЬЗОВАТЕЛЬ:
public class Users {

@Id
@Column(unique = true, nullable = false)
private String userId;

@Column(nullable = false)
private String password;

@Column(nullable = false)
private String propertyId; // single user can have multiple property

@Column(nullable = false, unique = true)
private String taxId; // single taxID for each propertyId

@Column(nullable = false)
private String name;

private String guardianName;

@Column(nullable = false, unique = true)
private String adhaarCard;

@Column(nullable = false, unique = true)
private String panCard;

@DateTimeFormat(pattern = "MM-dd-yy")
private LocalDate dob;

@Column(nullable = false)
private Integer age;

@Column(nullable = false)
private String address;

@Column(nullable = false)
private String role;

@Transient
private List
properties =new ArrayList();

@Transient
private List taxes =new ArrayList();

}

СОБСТВЕННОСТЬ
public class Property {

private String propertyId; // Unique Property ID (PIN) , will be our primary key for this table

private String userId; // for user_id, whose property it is

private String taxId; // particular tax_id for that specific property

private String ownerName; // Owner's Name

private String contactNumber; // Contact Number

private String address; // Property Address

private String tradeLicenseDetails; // Trade license details if applicable

@Transient
private List taxes =new ArrayList();

и НАЛОГ
public class Tax {

private String taxId; // Primary key for Tax Ledger entry

private String propertyId; // Foreign key from Property service

private String userId; // Foreign key from User service

private double taxAmount; // Amount of tax demanded

private double amountPaid; // Amount paid by the user

private LocalDate paymentDate; // Date when the payment was made
}

Я сделал их уникальными и случайными, а также сделал одинаковые объекты в своем пакете DTO для упрощения взаимодействия.
Теперь в моем UserServiceImpl я пытаюсь чтобы отобразить всю мою информацию о пользователе, касающуюся всей его собственности и налогов, связанных с ней.
@Service
public class UserServiceImpl implements UserService {

@Autowired
private UserRepository userRepository;

@Autowired
private ModelMapper modalMapper;

@Autowired
private Property_Management_Service property_service;

@Autowired
private Tax_Management_Service tax_service;

private Logger logger = LoggerFactory.getLogger(UserService.class);

@Override
public UserDto createUser(UserDto userDto) {

Users users = this.userDtoToUsers(userDto); // modal mapper class for converting User entity to UserDTO entity

Users saveUsers = this.userRepository.save(users);

return this.usersTouserDto(saveUsers);
}

@Override
public List getUser() {

List users = this.userRepository.findAll();

List userDtos = users.stream().map(user -> {
UserDto userDto = this.usersTouserDto(user);

// Fetching properties for this user using property_ID
List
propertyDtos = this.property_service.getPropertyById(user.getPropertyId());
userDto.setPropertiesDto(propertyDtos);

}).collect(Collectors.toList());
// Fetch tax data for each property
List taxDtos = propertyDtos.stream().map(property -> {
return this.tax_service.getTaxById(property.getTaxId());
}).collect(Collectors.toList());

userDto.setTaxesDto(taxDtos); // Set taxes in UserDto

return userDtos;
}

ошибка, которую я получаю в приведенном выше коде: «Отдельные маркеры в этой строке — несоответствие типов: невозможно преобразовать из List в List»
и это связано с
Property_Management_Service
@FeignClient(name = "PROPERTY-DATA-MANAGEMENT")
public interface Property_Management_Service {

// list all property data by property id
@GetMapping("api/property/v1/property/{propertyId}")
ResponseEntity
getPropertyById(@PathVariable String propertyId);
}

и Служба налогового_управления
@FeignClient(name = "TAX-DATA-MANAGEMENT")
public interface Tax_Management_Service {

// list tax record data by tax_id
@GetMapping("api/tax/v1/tax/{taxId}")
ResponseEntity getTaxById(@PathVariable String taxId);

}

Моя ошибка:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'serviceImpl': Error creating bean with name 'userServiceImpl' defined in file [D:\Project\Nagar Nigam\User-Data-Management\target\classes\com\user_dm\UM\services\UserServiceImpl.class]: Failed to instantiate [com.user_dm.UM.services.UserServiceImpl]: Constructor threw exception
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:788) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:768) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:145) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:509) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1439) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:599) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:975) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:971) ~[spring-context-6.1.12.jar:6.1.12]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:625) ~[spring-context-6.1.12.jar:6.1.12]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.3.3.jar:3.3.3]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.3.3.jar:3.3.3]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.3.3.jar:3.3.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.3.3.jar:3.3.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.3.3.jar:3.3.3]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.3.3.jar:3.3.3]
at com.user_dm.UM.UserDataManagementApplication.main(UserDataManagementApplication.java:14) ~[classes/:na]
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:580) ~[na:na]
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50) ~[spring-boot-devtools-3.3.3.jar:3.3.3]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userServiceImpl' defined in file [D:\Project\Nagar Nigam\User-Data-Management\target\classes\com\user_dm\UM\services\UserServiceImpl.class]: Failed to instantiate [com.user_dm.UM.services.UserServiceImpl]: Constructor threw exception
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1337) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:337) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:335) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:254) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1443) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1353) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.resolveFieldValue(AutowiredAnnotationBeanPostProcessor.java:785) ~[spring-beans-6.1.12.jar:6.1.12]
... 23 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.user_dm.UM.services.UserServiceImpl]: Constructor threw exception
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:221) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:94) ~[spring-beans-6.1.12.jar:6.1.12]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1331) ~[spring-beans-6.1.12.jar:6.1.12]
... 34 common frames omitted
Caused by: java.lang.Error: Unresolved compilation problems:
propertyDtos cannot be resolved
The method map(Function

Подробнее здесь: https://stackoverflow.com/questions/790 ... to-another
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»