繁体   English   中英

SpringBoot 微服务 InvalidDefinitionException

[英]SpringBoot microservice InvalidDefinitionException

我开发了一个微服务,当我 go 到达 postman ( http://localhost:8080/user/utenti/ ) 我得到这个错误 InvalidDefinitionException No serializer found for class org.hibernate发现创建 BeanSerializer(为避免异常,禁用 SerializationFeature.FAIL_ON_EMPTY_BEANS)(通过引用链:java.util.ArrayList[0]->com.application.dto.UserDto["applicationRoleID"]->com.poste.anagrafica.entity。角色$HibernateProxy$N0iZZA2I["hibernateLazyInitializer"])

你能帮我吗? 为了清楚起见,我附上了数据库的模式和类实体、dto 和 controller

在此处输入图像描述

实体类

"""

@Entity
@Table(name = "USERS")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
public class User implements Serializable {
@Id
@Column(name = "user_id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "created_date")
private LocalDateTime createdDate;

@Column(name = "deleted", nullable = false)
private Long number;

@Column(name = "modified_date")
private LocalDateTime modifiedDate;

@Column(name = "birth_place")
private String birthPlace;

@Column(name = "birthday")
private Date birthDay;

@Column(name = "canNominate")
private Long canNominate;

@Column(name = "email")
private String email;

@Column(name = "firstName")
private String firstName;

@Column(name= "fiscalCode")
private String fiscalCode;

@Column(name = "hiringDate")
private Date hiringDate;

@Column(name ="last_name")
private String lastName;

@Column(name = "matricola")
private String matricola;

@Column(name = "position")
private String position;

@Column(name = "registration_number")
private String registrationNumber;

@Column(name = "replaced")
private Long replaced;

@Column(name = "terminationDate")
private Date terminationDate;

@Column(name = "user_status")
private String userStatus;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "application_role_id")
private Role applicationRoleID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "company_id")
private Company companyID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "direction_id")
private Direction directions ;


@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "level_id")
private Levels levelID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "referent_id")
private User referentID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "role_id")
private Role roleID;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "task_id")
private EmployeeTask taskID;

} """

用户 DTO class

"""

@Data
public class UserDto {


private Long userId;


private LocalDateTime createdDate;

private Long number;

private LocalDateTime modifiedDate;


private String birthPlace;


private Date birthDay;


private Long canNominate;


private String email;

private String firstName;


private String fiscalCode;


private Date hiringDate;

private String lastName;


private String matricola;


private String position;

private String registrationNumber;


private Long replaced;


private Date terminationDate;


private String userStatus;


private Role applicationRoleID;


private Company companyID;


private Direction directions ;



private Levels levelID;

private User referentID;


private Role role;

private EmployeeTask taskID;

}

"""

controller class """

 @RestController
 @RequestMapping("/user")
 @Log
 public class UserController {

private static final Logger logger = LoggerFactory.getLogger(UserController.class);

@Autowired
UserService userService;

@GetMapping(value = "/cerca/{registration_number}", produces = "application/json")
public ResponseEntity<List<UserDto>> listUserByRegistrationNumber(@PathVariable("registration_number") String registrationNumber)
        throws ChangeSetPersister.NotFoundException
{
    log.info("****** Ottengo l'user con numeroRegistrazione " + registrationNumber + " *******");

    List<UserDto> user = userService.SelByRegistrationNumber(registrationNumber);



    return new ResponseEntity<List<UserDto>>(user, HttpStatus.OK);
}

@GetMapping(value = "/utenti", produces = "application/json")
public ResponseEntity<List<UserDto>> listAllUsers ()throws ChangeSetPersister.NotFoundException{


    List<UserDto> user = userService.SelTutti();



    return new ResponseEntity<List<UserDto>>(user, HttpStatus.OK);


}
}

"""

应用程序.properties

"""

spring.datasource.url = jdbc:oracle:thin:@192.134.2.82:1521/orcl

spring.datasource.username =admin
spring.datasource.password =zzzx
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver



# JPA settings
spring.jpa.database-platform=org.hibernate.dialect.Oracle12cDialect
spring.jpa.hibernate.use-new-id-generator-mappings=false
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming.implicit-       strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

"""

你可以试试

spring.jackson.serialization.fail-on-empty-beans=false

在你的 application.properties 中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM