我遇到一个问题,就是在有负载的情况下运行了大约一天后,Spring Boot服务突然无法创建连接。
我使用了标准的Spring Boot 2项目启动器。创建了一个休息控制器,一个模型,一个服务和一个存储库。
<Page.DataContext>
<vm:Pg7FirmwareUpdateViewModel/> <= Here
</Page.DataContext>
<Page.Resources>
<!-- Sets Progress Bar View -->
<DataTemplate DataType="{x:Type svm:ErrorViewModel}"> <= Here
<sv:ErrorView/>
</DataTemplate>
</Page.Resources>
回购
@Entity
@Table(name = "partners")
public class Partner {
/** Unique identifier. */
@Id
@JsonProperty("id")
private long id;
/** Partner name. */
@JsonProperty("name")
private String name;
/**
* Default constructor. Not usable publicly.
*/
protected Partner() {
}
// etc...
}
服务
/**
* Partner repo.
*/
public interface PartnerRepository extends CrudRepository<Partner, Long> {
}
控制器
@Service
public class PartnersService {
/** Access to Partner repo. */
@Autowired
private PartnerRepository partnerRepo;
/**
* Get partner data.
*
* @param id Partner identifier.
* @return Partner instance, or null if not found.
*/
public Partner getPartner(final long id) throws ServiceException {
if (id <= 0) {
throw new ServiceException("Please enter a valid partner identifier.");
}
final Optional<Partner> partner = partnerRepo.findById(id);
return partner.orElse(null);
}
}
一切都是默认配置。在生产中使用了一段时间后,我得到:
@RestController
public class PartnerController extends BaseController {
/** Partners service. */
@Autowired
private PartnersService partnersService;
@RequestMapping(value = "/partners/api/v1/partners/{id}", method = GET)
public ResponseEntity<FilldResponse> getPartner(@PathVariable final long id) {
final FilldResponse response = new FilldResponse();
HttpStatus httpStatus = HttpStatus.OK;
try {
final Partner partner = partnersService.getPartner(id);
if (partner != null) {
response.setData(partner);
response.setMessage("Partner retrieved successfully.");
} else {
response.setMessage("Partner not found.");
response.setStatusCode(4000);
response.setStatus(false);
httpStatus = HttpStatus.NOT_FOUND;
}
} catch (Exception ex) {
response.setStatus(false);
response.setMessage(ex.getMessage());
response.setStatusCode(4000);
httpStatus = HttpStatus.BAD_REQUEST;
}
return new ResponseEntity<>(response, httpStatus);
}
}
它在AWS中作为docker映像运行。
是否存在可能导致此问题的未配置的已知问题或配置?