Вот мой контроллер:
package pizzainthecloud.pizzaplace.controller;
import com.heavyweightsoftware.exception.HeavyweightException;
import org.addycaddy.client.dto.ContactPointDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pizzainthecloud.pizzaplace.service.AddressValidationService;
import java.util.Random;
@CrossOrigin
@RestController(value = "/address")
public class AddressController {
public static final String KEY_ADDRESS = "address";
private static final Logger log = LoggerFactory.getLogger(AddressController.class);
@Autowired
private AddressValidationService addressValidationService;
private Random random = new Random();
private ContactPointDto[] contactPointDtos = new ContactPointDto[] {
getContactPoint1(),
getContactPoint2(),
getContactPoint3(),
getContactPoint4(),
getContactPoint5()
};
@RequestMapping(value = "/validate", method = RequestMethod.POST)
@ResponseBody
public ContactPointDto[] validate(@RequestParam(KEY_ADDRESS) ContactPointDto address) {
ContactPointDto[] result;
// try {
// result = addressValidationService.validate(address);
// } catch (HeavyweightException he) {
// String msg = "Error validating address:" + address;
// log.error(msg, he);
// result = new ContactPointDto[0];
// }
if (random.nextBoolean()) {
//sometimes return just one
int idx = random.nextInt(contactPointDtos.length);
result = new ContactPointDto[] {contactPointDtos[idx]};
}
else {
result = contactPointDtos;
}
return result;
}
public static ContactPointDto getContactPoint1() {
ContactPointDto result = new ContactPointDto();
result.setStreet1("1 Testy Person Way");
result.setCity("Testerville");
result.setState("KY");
result.setPostalCode("40419");
return result;
}
public static ContactPointDto getContactPoint2() {
ContactPointDto result = new ContactPointDto();
result.setStreet1("2 Testy Person Way");
result.setCity("Testerville");
result.setState("KY");
result.setPostalCode("40419");
return result;
}
public static ContactPointDto getContactPoint3() {
ContactPointDto result = new ContactPointDto();
result.setStreet1("3 Testy Person Way");
result.setCity("Testerville");
result.setState("KY");
result.setPostalCode("40419");
return result;
}
public static ContactPointDto getContactPoint4() {
ContactPointDto result = new ContactPointDto();
result.setStreet1("4 Testy Person Way");
result.setCity("Testerville");
result.setState("KY");
result.setPostalCode("40419");
return result;
}
public static ContactPointDto getContactPoint5() {
ContactPointDto result = new ContactPointDto();
result.setStreet1("5 Testy Person Way");
result.setCity("Testerville");
result.setState("KY");
result.setPostalCode("40419");
return result;
}
}
Когда я запускаю свое приложение Spring Boot, я получаю:
2019-06-10 13:32:28.368 DEBUG 4224 --- [qtp531576940-32] o.s.web.servlet.DispatcherServlet : DispatcherServlet with name 'dispatcherServlet' processing OPTIONS request for [/address/validate]
2019-06-10 13:32:28.368 DEBUG 4224 --- [qtp531576940-32] o.s.b.a.e.mvc.EndpointHandlerMapping : Looking up handler method for path /address/validate
2019-06-10 13:32:28.370 DEBUG 4224 --- [qtp531576940-32] o.s.b.a.e.mvc.EndpointHandlerMapping : Did not find handler method for [/address/validate]
2019-06-10 13:32:28.370 DEBUG 4224 --- [qtp531576940-32] s.w.s.m.m.a.RequestMappingHandlerMapping : Looking up handler method for path /address/validate
2019-06-10 13:32:28.372 DEBUG 4224 --- [qtp531576940-32] s.w.s.m.m.a.RequestMappingHandlerMapping : Did not find handler method for [/address/validate]
2019-06-10 13:32:28.372 DEBUG 4224 --- [qtp531576940-32] o.s.w.s.handler.SimpleUrlHandlerMapping : Matching patterns for request [/address/validate] are [/**]
2019-06-10 13:32:28.373 DEBUG 4224 --- [qtp531576940-32] o.s.w.s.handler.SimpleUrlHandlerMapping : URI Template variables for request [/address/validate] are {}
2019-06-10 13:32:28.373 DEBUG 4224 --- [qtp531576940-32] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapping [/address/validate] to HandlerExecutionChain with handler [ResourceHttpRequestHandler [locations=[ServletContext resource [/], class path resource [META-INF/resources/], class path resource [resources/], class path resource [static/], class path resource [public/]], resolvers=[org.springframework.web.servlet.resource.PathResourceResolver@7ec5d3e1]]] and 1 interceptor
Так что, похоже, он не отображает мой контроллер.Я включил:
@SpringBootApplication
@EnableTransactionManagement
@ComponentScan(basePackageClasses = {Application.class, PizzaPlaceController.class} )
@EnableScheduling
public class Application {
В моем классе приложения, где PizzaPlaceController
работает и находится в том же пакете, что и AddressController
, и он находит PizzaPlaceController
просто отлично.
Ответыздесь бесполезно: RequestMappingHandlerMapping.getHandlerInternal: 230 - Не найден метод обработчика для
Добавление AddressController
в список @ComponentScan
ничего не изменило.