Это мой третий личный проект с пружинной загрузкой, я использую на 99% ту же конфигурацию, что и раньше, поэтому понятия не имею, почему я получаю эту ошибку.
Запуск проекта просто хорошо, но как только я делаю какое-либо обращение к имеющемуся у меня уникальному @RestController, он сразу же получает нулевую ошибку. Эта конечная точка получает код страны альфа-2 + название города + желаемый IP-адрес. Если IP-адрес не указан, он принимает IP-адрес клиента, который используется в качестве параметра для @Service, от которого я получаю ноль. После этого контроллер должен выполнить множество других действий, прежде чем отправить ожидаемый результат клиенту, но он никогда не достигает этой точки, поскольку в этом @Service возникло нулевое исключение.
Это петиция, которую я пытаюсь создать. на:
http://localhost:8080/apiv1/get-distanc ... 135.184.38
There was an unexpected error (type=Internal Server Error, status=500).
Cannot invoke "me.givo.distancebetweenus.getdistance.services.CurrentLocationService.getCurrentLocation(String)" because "this.currentLocationService" is null
java.lang.NullPointerException: Cannot invoke "me.givo.distancebetweenus.getdistance.services.CurrentLocationService.getCurrentLocation(String)" because "this.currentLocationService" i s n u l l < b r / > a t m e . g i v o . d i s t a n c e b e t w e e n u s . g e t d i s t a n c e . c o n t r o l l e r s . D i s t a n c e C o n t r o l l e r . g e t D i s t a n c e ( D i s t a n c e C o n t r o l l e r . j a v a : 5 3 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e 0 ( N a t i v e M e t h o d ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e ( N a t i v e M e t h o d A c c e s s o r I m p l . j a v a : 7 7 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . D e l e g a t i n g M e t h o d A c c e s s o r I m p l . i n v o k e ( D e l e g a t i n g M e t h o d A c c e s s o r I m p l . j a v a : 4 3 ) < b r / > a t j a v a . b a s e / j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( M e t h o d . j a v a : 5 6 8 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . m e t h o d . s u p p o r t . I n v o c a b l e H a n d l e r M e t h o d . d o I n v o k e ( I n v o c a b l e H a n d l e r M e t h o d . j a v a : 2 0 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . m e t h o d . s u p p o r t . I n v o c a b l e H a n d l e r M e t h o d . i n v o k e F o r R e q u e s t ( I n v o c a b l e H a n d l e r M e t h o d . j a v a : 1 5 0 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . S e r v l e t I n v o c a b l e H a n d l e r M e t h o d . i n v o k e A n d H a n d l e ( S e r v l e t I n v o c a b l e H a n d l e r M e t h o d . j a v a : 1 1 7 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . R e q u e s t M a p p i n g H a n d l e r A d a p t e r . i n v o k e H a n d l e r M e t h o d ( R e q u e s t M a p p i n g H a n d l e r A d a p t e r . j a v a : 8 9 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . R e q u e s t M a p p i n g H a n d l e r A d a p t e r . h a n d l e I n t e r n a l ( R e q u e s t M a p p i n g H a n d l e r A d a p t e r . j a v a : 8 0 8 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . A b s t r a c t H a n d l e r M e t h o d A d a p t e r . h a n d l e ( A b s t r a c t H a n d l e r M e t h o d A d a p t e r . j a v a : 8 7 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . D i s p a t c h e r S e r v l e t . d o D i s p a t c h ( D i s p a t c h e r S e r v l e t . j a v a : 1 0 6 7 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . D i s p a t c h e r S e r v l e t . d o S e r v i c e ( D i s p a t c h e r S e r v l e t . j a v a : 9 6 3 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . F r a m e w o r k S e r v l e t . p r o c e s s R e q u e s t ( F r a m e w o r k S e r v l e t . j a v a : 1 0 0 6 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . F r a m e w o r k S e r v l e t . d o G e t ( F r a m e w o r k S e r v l e t . j a v a : 8 9 8 ) < b r / > a t j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t . s e r v i c e ( H t t p S e r v l e t . j a v a : 6 5 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . F r a m e w o r k S e r v l e t . s e r v i c e ( F r a m e w o r k S e r v l e t . j a v a : 8 8 3 ) < b r / > a t j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t . s e r v i c e ( H t t p S e r v l e t . j a v a : 7 6 4 ) < b r / > a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 2 2 7 ) < b r / > a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . d o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 1 6 2 ) < b r / > a t o r g . a p a c h e . t o m c a t . w e b s o c k e t . s e r v e r . W s F i l t e r . d o F i l t e r ( W s F i l t e r . j a v a : 5 3 ) < b r / > a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 1 8 9 ) < b r / > a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t erChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
Это мой контроллер:
package me.givo.distancebetweenus.getdistance.controllers;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import me.givo.distancebetweenus.getdistance.dtos.CityDto;
import me.givo.distancebetweenus.getdistance.dtos.CountryDto;
import me.givo.distancebetweenus.getdistance.entities.CityEntity;
import me.givo.distancebetweenus.getdistance.entities.CountryEntity;
import me.givo.distancebetweenus.getdistance.models.ApiCurrentLocationResponse;
import me.givo.distancebetweenus.getdistance.models.Coordinate;
import me.givo.distancebetweenus.getdistance.models.DistanceResponse;
import me.givo.distancebetweenus.getdistance.repositories.ICitiesRepository;
import me.givo.distancebetweenus.getdistance.repositories.ICountriesRepository;
import me.givo.distancebetweenus.getdistance.services.CurrentLocationService;
import org.modelmapper.ModelMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@RequestMapping("/apiv1")
@Validated
@RestController
public class DistanceController {
private final CurrentLocationService currentLocationService;
private final ICitiesRepository citiesRepository;
private final ICountriesRepository countriesRepository;
private final ModelMapper modelMapper;
public DistanceController(CurrentLocationService currentLocationService, ICitiesRepository citiesRepository,
ICountriesRepository countryRepository, ModelMapper modelMapper) {
this.currentLocationService = currentLocationService;
this.citiesRepository = citiesRepository;
this.countriesRepository = countryRepository;
this.modelMapper = modelMapper;
}
@GetMapping("/get-distance")
@ResponseBody
private ResponseEntity getDistance(
@RequestParam(required = true, name = "country") @Min(2) @Max(2) String country,
@RequestParam(required = true, name = "city") String city,
@RequestParam(required = false, name = "ip") @Min(7) @Max(15) String ip,
HttpServletRequest request) {
ApiCurrentLocationResponse currentLocation;
if (ip == null || ip.isEmpty()) {
String requestIP = request.getRemoteAddr();
System.out.println(requestIP);
try {
currentLocation = currentLocationService.getCurrentLocation(requestIP);
} catch (Exception e) {
System.out.println(e.getMessage());
}
} else {
try {
currentLocation = currentLocationService.getCurrentLocation(ip);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
CountryEntity countryEntity = countriesRepository.getById(country);
CityEntity cityEntity = citiesRepository.getByNameAndCode(city, country);
CountryDto countryDto = convertToCountryDto(countryEntity);
CityDto cityDto = convertToCityDto(cityEntity);
Coordinate currentLocationCoordinate = new Coordinate(currentLocation);
Coordinate destinationCoordinate = new Coordinate(cityDto);
Double distance = currentLocationCoordinate.distanceBetweenUsKm(destinationCoordinate);
DistanceResponse response = new DistanceResponse(countryDto, cityDto, distance);
return ResponseEntity.status(HttpStatus.OK).body(response);
}
private CityDto convertToCityDto(CityEntity cityEntity) {
return modelMapper.map(cityEntity, CityDto.class);
}
private CountryDto convertToCountryDto(CountryEntity countryEntity) {
return modelMapper.map(countryEntity, CountryDto.class);
}
}
Это «нулевой» @Service:
package me.givo.distancebetweenus.getdistance.services;
import me.givo.distancebetweenus.getdistance.models.ApiCurrentLocationResponse;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
@Service
public class CurrentLocationService {
private final WebClient.Builder webClient;
private final String key = "fakekey347834834892923fake";
public CurrentLocationService(WebClient.Builder webClient) {
this.webClient = webClient;
}
public ApiCurrentLocationResponse getCurrentLocation(String requestIP) {
String url = "https://api.fakeapi.app/json/";
return webClient.baseUrl(url).build().get()
.uri(uriBuilder -> uriBuilder
.path(requestIP)
.queryParam("apikey", key)
.build())
.retrieve()
.bodyToMono(ApiCurrentLocationResponse.class)
.block();
}
}
Спасибо за вашу помощь. Если требуется какая-либо другая информация, пожалуйста, дайте мне знать. Спасибо!
----------------Редактировать --------------------
комментарий Шивама дал мне идею пометить @Autowired мои инъекции, поэтому я сделал это, и я больше не получаю нулевое исключение в @Service, вместо этого оно находится в ICountriesRepository, что является всего лишь следующей строкой кода в моем @RestController..
Вот изменения, которые я внес:
public class DistanceController {
private final CurrentLocationService currentLocationService;
private final ICitiesRepository citiesRepository;
private final ICountriesRepository countriesRepository;
private final ModelMapper modelMapper;
@Autowired
public DistanceController(CurrentLocationService currentLocationService, ICitiesRepository citiesRepository,
ICountriesRepository countriesRepository, ModelMapper modelMapper) {
this.currentLocationService = currentLocationService;
this.citiesRepository = citiesRepository;
this.countriesRepository = countriesRepository;
this.modelMapper = modelMapper;
}
Это «новый» журнал ошибок:
There was an unexpected error (type=Internal Server Error, status=500).
Cannot invoke "me.givo.distancebetweenus.getdistance.repositories.ICountriesRepository.getById(Object)" because "this.countriesRepository" is null
java.lang.NullPointerException: Cannot invoke "me.givo.distancebetweenus.getdistance.repositories.ICountriesRepository.getById(Object)" because "this.countriesRepository" i s n u l l < b r / > a t m e . g i v o . d i s t a n c e b e t w e e n u s . g e t d i s t a n c e . c o n t r o l l e r s . D i s t a n c e C o n t r o l l e r . g e t D i s t a n c e ( D i s t a n c e C o n t r o l l e r . j a v a : 7 2 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e 0 ( N a t i v e M e t h o d ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e ( N a t i v e M e t h o d A c c e s s o r I m p l . j a v a : 7 7 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . D e l e g a t i n g M e t h o d A c c e s s o r I m p l . i n v o k e ( D e l e g a t i n g M e t h o d A c c e s s o r I m p l . j a v a : 4 3 ) < b r / > a t j a v a . b a s e / j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( M e t h o d . j a v a : 5 6 8 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . m e t h o d . s u p p o r t . I n v o c a b l e H a n d l e r M e t h o d . d o I n v o k e ( I n v o c a b l e H a n d l e r M e t h o d . j a v a : 2 0 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . m e t h o d . s u p p o r t . I n v o c a b l e H a n d l e r M e t h o d . i n v o k e F o r R e q u e s t ( I n v o c a b l e H a n d l e r M e t h o d . j a v a : 1 5 0 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . S e r v l e t I n v o c a b l e H a n d l e r M e t h o d . i n v o k e A n d H a n d l e ( S e r v l e t I n v o c a b l e H a n d l e r M e t h o d . j a v a : 1 1 7 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . R e q u e s t M a p p i n g H a n d l e r A d a p t e r . i n v o k e H a n d l e r M e t h o d ( R e q u e s t M a p p i n g H a n d l e r A d a p t e r . j a v a : 8 9 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . R e q u e s t M a p p ingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
Есть код ICountriesRepository:
package me.givo.distancebetweenus.getdistance.repositories;
import me.givo.distancebetweenus.getdistance.entities.CountryEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ICountriesRepository extends JpaRepository {
}
Кроме того, я добавляю код @Configuration, созданный мной для ModelMapper:
package me.givo.distancebetweenus.getdistance.config;
import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Config {
@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
}
Подробнее здесь: https://stackoverflow.com/questions/701 ... -injection
Нулевое исключение @Service в Spring @RestController с использованием инъекции конструктора ⇐ JAVA
Программисты JAVA общаются здесь
1719600122
Anonymous
Это мой третий личный проект с пружинной загрузкой, я использую на 99% ту же конфигурацию, что и раньше, поэтому понятия не имею, почему я получаю эту ошибку.
Запуск проекта просто хорошо, но как только я делаю какое-либо обращение к имеющемуся у меня уникальному @RestController, он сразу же получает нулевую ошибку. Эта конечная точка получает код страны альфа-2 + название города + желаемый IP-адрес. Если IP-адрес не указан, он принимает IP-адрес клиента, который используется в качестве параметра для @Service, от которого я получаю ноль. После этого контроллер должен выполнить множество других действий, прежде чем отправить ожидаемый результат клиенту, но он никогда не достигает этой точки, поскольку в этом @Service возникло нулевое исключение.
Это петиция, которую я пытаюсь создать. на:
http://localhost:8080/apiv1/get-distance?country=af&city=Qalat&ip=150.135.184.38
There was an unexpected error (type=Internal Server Error, status=500).
Cannot invoke "me.givo.distancebetweenus.getdistance.services.CurrentLocationService.getCurrentLocation(String)" because "this.currentLocationService" is null
java.lang.NullPointerException: Cannot invoke "me.givo.distancebetweenus.getdistance.services.CurrentLocationService.getCurrentLocation(String)" because "this.currentLocationService" i s n u l l < b r / > a t m e . g i v o . d i s t a n c e b e t w e e n u s . g e t d i s t a n c e . c o n t r o l l e r s . D i s t a n c e C o n t r o l l e r . g e t D i s t a n c e ( D i s t a n c e C o n t r o l l e r . j a v a : 5 3 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e 0 ( N a t i v e M e t h o d ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e ( N a t i v e M e t h o d A c c e s s o r I m p l . j a v a : 7 7 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . D e l e g a t i n g M e t h o d A c c e s s o r I m p l . i n v o k e ( D e l e g a t i n g M e t h o d A c c e s s o r I m p l . j a v a : 4 3 ) < b r / > a t j a v a . b a s e / j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( M e t h o d . j a v a : 5 6 8 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . m e t h o d . s u p p o r t . I n v o c a b l e H a n d l e r M e t h o d . d o I n v o k e ( I n v o c a b l e H a n d l e r M e t h o d . j a v a : 2 0 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . m e t h o d . s u p p o r t . I n v o c a b l e H a n d l e r M e t h o d . i n v o k e F o r R e q u e s t ( I n v o c a b l e H a n d l e r M e t h o d . j a v a : 1 5 0 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . S e r v l e t I n v o c a b l e H a n d l e r M e t h o d . i n v o k e A n d H a n d l e ( S e r v l e t I n v o c a b l e H a n d l e r M e t h o d . j a v a : 1 1 7 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . R e q u e s t M a p p i n g H a n d l e r A d a p t e r . i n v o k e H a n d l e r M e t h o d ( R e q u e s t M a p p i n g H a n d l e r A d a p t e r . j a v a : 8 9 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . R e q u e s t M a p p i n g H a n d l e r A d a p t e r . h a n d l e I n t e r n a l ( R e q u e s t M a p p i n g H a n d l e r A d a p t e r . j a v a : 8 0 8 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . A b s t r a c t H a n d l e r M e t h o d A d a p t e r . h a n d l e ( A b s t r a c t H a n d l e r M e t h o d A d a p t e r . j a v a : 8 7 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . D i s p a t c h e r S e r v l e t . d o D i s p a t c h ( D i s p a t c h e r S e r v l e t . j a v a : 1 0 6 7 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . D i s p a t c h e r S e r v l e t . d o S e r v i c e ( D i s p a t c h e r S e r v l e t . j a v a : 9 6 3 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . F r a m e w o r k S e r v l e t . p r o c e s s R e q u e s t ( F r a m e w o r k S e r v l e t . j a v a : 1 0 0 6 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . F r a m e w o r k S e r v l e t . d o G e t ( F r a m e w o r k S e r v l e t . j a v a : 8 9 8 ) < b r / > a t j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t . s e r v i c e ( H t t p S e r v l e t . j a v a : 6 5 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . F r a m e w o r k S e r v l e t . s e r v i c e ( F r a m e w o r k S e r v l e t . j a v a : 8 8 3 ) < b r / > a t j a v a x . s e r v l e t . h t t p . H t t p S e r v l e t . s e r v i c e ( H t t p S e r v l e t . j a v a : 7 6 4 ) < b r / > a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 2 2 7 ) < b r / > a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . d o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 1 6 2 ) < b r / > a t o r g . a p a c h e . t o m c a t . w e b s o c k e t . s e r v e r . W s F i l t e r . d o F i l t e r ( W s F i l t e r . j a v a : 5 3 ) < b r / > a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t e r C h a i n . i n t e r n a l D o F i l t e r ( A p p l i c a t i o n F i l t e r C h a i n . j a v a : 1 8 9 ) < b r / > a t o r g . a p a c h e . c a t a l i n a . c o r e . A p p l i c a t i o n F i l t erChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
Это мой контроллер:
package me.givo.distancebetweenus.getdistance.controllers;
import javax.servlet.http.HttpServletRequest;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import me.givo.distancebetweenus.getdistance.dtos.CityDto;
import me.givo.distancebetweenus.getdistance.dtos.CountryDto;
import me.givo.distancebetweenus.getdistance.entities.CityEntity;
import me.givo.distancebetweenus.getdistance.entities.CountryEntity;
import me.givo.distancebetweenus.getdistance.models.ApiCurrentLocationResponse;
import me.givo.distancebetweenus.getdistance.models.Coordinate;
import me.givo.distancebetweenus.getdistance.models.DistanceResponse;
import me.givo.distancebetweenus.getdistance.repositories.ICitiesRepository;
import me.givo.distancebetweenus.getdistance.repositories.ICountriesRepository;
import me.givo.distancebetweenus.getdistance.services.CurrentLocationService;
import org.modelmapper.ModelMapper;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@RequestMapping("/apiv1")
@Validated
@RestController
public class DistanceController {
private final CurrentLocationService currentLocationService;
private final ICitiesRepository citiesRepository;
private final ICountriesRepository countriesRepository;
private final ModelMapper modelMapper;
public DistanceController(CurrentLocationService currentLocationService, ICitiesRepository citiesRepository,
ICountriesRepository countryRepository, ModelMapper modelMapper) {
this.currentLocationService = currentLocationService;
this.citiesRepository = citiesRepository;
this.countriesRepository = countryRepository;
this.modelMapper = modelMapper;
}
@GetMapping("/get-distance")
@ResponseBody
private ResponseEntity getDistance(
@RequestParam(required = true, name = "country") @Min(2) @Max(2) String country,
@RequestParam(required = true, name = "city") String city,
@RequestParam(required = false, name = "ip") @Min(7) @Max(15) String ip,
HttpServletRequest request) {
ApiCurrentLocationResponse currentLocation;
if (ip == null || ip.isEmpty()) {
String requestIP = request.getRemoteAddr();
System.out.println(requestIP);
try {
currentLocation = currentLocationService.getCurrentLocation(requestIP);
} catch (Exception e) {
System.out.println(e.getMessage());
}
} else {
try {
currentLocation = currentLocationService.getCurrentLocation(ip);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
CountryEntity countryEntity = countriesRepository.getById(country);
CityEntity cityEntity = citiesRepository.getByNameAndCode(city, country);
CountryDto countryDto = convertToCountryDto(countryEntity);
CityDto cityDto = convertToCityDto(cityEntity);
Coordinate currentLocationCoordinate = new Coordinate(currentLocation);
Coordinate destinationCoordinate = new Coordinate(cityDto);
Double distance = currentLocationCoordinate.distanceBetweenUsKm(destinationCoordinate);
DistanceResponse response = new DistanceResponse(countryDto, cityDto, distance);
return ResponseEntity.status(HttpStatus.OK).body(response);
}
private CityDto convertToCityDto(CityEntity cityEntity) {
return modelMapper.map(cityEntity, CityDto.class);
}
private CountryDto convertToCountryDto(CountryEntity countryEntity) {
return modelMapper.map(countryEntity, CountryDto.class);
}
}
Это «нулевой» @Service:
package me.givo.distancebetweenus.getdistance.services;
import me.givo.distancebetweenus.getdistance.models.ApiCurrentLocationResponse;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
@Service
public class CurrentLocationService {
private final WebClient.Builder webClient;
private final String key = "fakekey347834834892923fake";
public CurrentLocationService(WebClient.Builder webClient) {
this.webClient = webClient;
}
public ApiCurrentLocationResponse getCurrentLocation(String requestIP) {
String url = "https://api.fakeapi.app/json/";
return webClient.baseUrl(url).build().get()
.uri(uriBuilder -> uriBuilder
.path(requestIP)
.queryParam("apikey", key)
.build())
.retrieve()
.bodyToMono(ApiCurrentLocationResponse.class)
.block();
}
}
Спасибо за вашу помощь. Если требуется какая-либо другая информация, пожалуйста, дайте мне знать. Спасибо!
----------------Редактировать --------------------
комментарий Шивама дал мне идею пометить @Autowired мои инъекции, поэтому я сделал это, и я больше не получаю нулевое исключение в @Service, вместо этого оно находится в ICountriesRepository, что является всего лишь следующей строкой кода в моем @RestController..
Вот изменения, которые я внес:
public class DistanceController {
private final CurrentLocationService currentLocationService;
private final ICitiesRepository citiesRepository;
private final ICountriesRepository countriesRepository;
private final ModelMapper modelMapper;
@Autowired
public DistanceController(CurrentLocationService currentLocationService, ICitiesRepository citiesRepository,
ICountriesRepository countriesRepository, ModelMapper modelMapper) {
this.currentLocationService = currentLocationService;
this.citiesRepository = citiesRepository;
this.countriesRepository = countriesRepository;
this.modelMapper = modelMapper;
}
Это «новый» журнал ошибок:
There was an unexpected error (type=Internal Server Error, status=500).
Cannot invoke "me.givo.distancebetweenus.getdistance.repositories.ICountriesRepository.getById(Object)" because "this.countriesRepository" is null
java.lang.NullPointerException: Cannot invoke "me.givo.distancebetweenus.getdistance.repositories.ICountriesRepository.getById(Object)" because "this.countriesRepository" i s n u l l < b r / > a t m e . g i v o . d i s t a n c e b e t w e e n u s . g e t d i s t a n c e . c o n t r o l l e r s . D i s t a n c e C o n t r o l l e r . g e t D i s t a n c e ( D i s t a n c e C o n t r o l l e r . j a v a : 7 2 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e 0 ( N a t i v e M e t h o d ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e M e t h o d A c c e s s o r I m p l . i n v o k e ( N a t i v e M e t h o d A c c e s s o r I m p l . j a v a : 7 7 ) < b r / > a t j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . D e l e g a t i n g M e t h o d A c c e s s o r I m p l . i n v o k e ( D e l e g a t i n g M e t h o d A c c e s s o r I m p l . j a v a : 4 3 ) < b r / > a t j a v a . b a s e / j a v a . l a n g . r e f l e c t . M e t h o d . i n v o k e ( M e t h o d . j a v a : 5 6 8 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . m e t h o d . s u p p o r t . I n v o c a b l e H a n d l e r M e t h o d . d o I n v o k e ( I n v o c a b l e H a n d l e r M e t h o d . j a v a : 2 0 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . m e t h o d . s u p p o r t . I n v o c a b l e H a n d l e r M e t h o d . i n v o k e F o r R e q u e s t ( I n v o c a b l e H a n d l e r M e t h o d . j a v a : 1 5 0 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . S e r v l e t I n v o c a b l e H a n d l e r M e t h o d . i n v o k e A n d H a n d l e ( S e r v l e t I n v o c a b l e H a n d l e r M e t h o d . j a v a : 1 1 7 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . R e q u e s t M a p p i n g H a n d l e r A d a p t e r . i n v o k e H a n d l e r M e t h o d ( R e q u e s t M a p p i n g H a n d l e r A d a p t e r . j a v a : 8 9 5 ) < b r / > a t o r g . s p r i n g f r a m e w o r k . w e b . s e r v l e t . m v c . m e t h o d . a n n o t a t i o n . R e q u e s t M a p p ingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1067)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:655)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:764)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:197)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:540)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:135)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:357)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:382)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:895)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1722)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:833)
Есть код ICountriesRepository:
package me.givo.distancebetweenus.getdistance.repositories;
import me.givo.distancebetweenus.getdistance.entities.CountryEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface ICountriesRepository extends JpaRepository {
}
Кроме того, я добавляю код @Configuration, созданный мной для ModelMapper:
package me.givo.distancebetweenus.getdistance.config;
import org.modelmapper.ModelMapper;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Config {
@Bean
public ModelMapper modelMapper() {
return new ModelMapper();
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/70143003/null-exception-service-in-a-spring-restcontroller-using-constructor-injection[/url]
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Должен быть одним из: service.start_sticky_compatibility, service.start_sticky, service.start_not_sticky, service.start_
Гость » » в форуме JAVAКогда у меня есть:
public int onStartCommand(Intent intent, int flags, int startId) {
try {
player.start();
isRunning = true;
}
catch(Exception e) {
isRunning = false;
player.stop();
}
return 1;
}
Я получаю следующую «ошибку» для возврата 1 :... - 0 Ответы
- 24 Просмотры
-
Последнее сообщение Гость
-
-
-
Должен быть одним из: service.start_sticky_compatibility, service.start_sticky, service.start_not_sticky, service.start_
Гость » » в форуме AndroidКогда у меня есть:
public int onStartCommand(Intent intent, int flags, int startId) {
try {
player.start();
isRunning = true;
}
catch(Exception e) {
isRunning = false;
player.stop();
}
return 1;
}
Я получаю следующую «ошибку» для возврата 1 :... - 0 Ответы
- 29 Просмотры
-
Последнее сообщение Гость
-
-
-
Java Service Wrapper во время запуска JAR Application FOM Service Service
Anonymous » » в форуме JAVAУ меня есть приложение JAR, которое обрабатывает и преобразует файл в файл CSV. Я сделал это, чтобы запуститься в службу Windows с помощью Java Service Orbper. Он успешно установил мое приложение JAR, когда я запускаю файл installApp-nt. Bat и... - 0 Ответы
- 53 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Можно ли использовать записи Java с аннотациями @Service/@RestController?
Anonymous » » в форуме JAVAЯ бы предпочел это в виде записи, поскольку там меньше шаблонов, но возникнут ли проблемы?
IntelliJ предлагает мне превратить базовый класс Java @Service следующим образом:
@Service
public class LocationService {
private final PlaceRepository... - 0 Ответы
- 17 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Spring Boot Service Service не может найти таблицу базы данных
Anonymous » » в форуме JAVAЯ создаю новое приложение Spring Boot 3.14 для себя. У меня есть предыдущее приложение Spring Boot 3.0.5, которое не имеет этой проблемы.@SpringBootApplication
public class JobSearchApplication {
public static void main(String[] args) {... - 0 Ответы
- 15 Просмотры
-
Последнее сообщение Anonymous
-
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...