一个Java package-private 中不为 public。无法从外部软件包访问问题的解决
在一个java项目中,有个类名 UserLoginResponse 飘红了
package com.crmeb.admin.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Builder;
import java.util.Date;
@Data
@Builder
@ApiModel(value = "用户登录响应")
public class UserLoginResponse {
@ApiModelProperty(value = "状态码")
private int code;
@ApiModelProperty(value = "消息")
private String message;
@ApiModelProperty(value = "时间戳")
private long timestamp;
@ApiModelProperty(value = "用户登录信息")
private UserLoginInfo userLoginInfo;
}
提示信息是
'UserLoginResponse(int, java.lang.String, long, com.crmeb.admin.dto.UserLoginInfo)' 在 'com.crmeb.admin.dto.UserLoginResponse' 中不为 public。无法从外部软件包访问
然后UserLoginResponse前面有个package-private修饰,这就很奇怪了,它是public的啊,
后来才知道,是它里面的一个类UserLoginInfo没有设为public ,
改为这样就ok了:
package com.crmeb.admin.dto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.util.Date;
@Data
@Accessors(chain = true)
@ApiModel(value = "UserLoginResponse对象", description = "用户登录响应")
public class UserLoginResponse {
@ApiModelProperty(value = "状态码", example = "200")
private int code;
@ApiModelProperty(value = "消息", example = "登录成功")
private String message;
@ApiModelProperty(value = "时间戳", example = "1629170292000")
private long timestamp;
@ApiModelProperty(value = "用户登录信息")
private UserLoginInfo userLoginInfo;
@Data
@Accessors(chain = true)
@ApiModel(value = "UserLoginInfo对象", description = "用户登录信息详情")
public static class UserLoginInfo {
@ApiModelProperty(value = "用户ID", example = "1")
private Integer uid;
@ApiModelProperty(value = "登录令牌", example = "eyJhbGciOiJIUzI1NiJ9...")
private String token;
}
}
原文地址:https://blog.csdn.net/wuzuyu365/article/details/143744528
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!