Answer the question
In order to leave comments, you need to log in
Why can endpoints be launched from only one rest controller?
Hello. Please help me solve the following problem.
I am writing a RESTFul application in spring.
This is how I set up the web config
public class AppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(AppConfig.class);
ctx.setServletContext(container);
ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
}
@RestController
public class MainRestController {
static final Logger log = LogManager.getLogger(MainRestController.class);
@Autowired
private UserService userService;
@Autowired
private GroupService groupService;
@Autowired
private RoomService roomService;
@Autowired
private UserEntityToUserDTO userEntityToUserDTO;
@RequestMapping(value = "/", method = RequestMethod.GET)
public String homePage() {
return "index";
}
.....
@RestController
public class UserController {
private static Logger logger = LogManager.getLogger(UserController.class);
@Autowired
UserService userService;
@Autowired
UserEntityToUserDTO userToUserDTO;
@Autowired
UserDTOtoUserEntity userDTOtoUser;
@Autowired
GroupService groupService;
@RequestMapping(value = "/getUserByCredentials", method = RequestMethod.GET)
public ResponseEntity<UserDTO> getUserByCredentials(HttpServletRequest req,
@RequestParam(value = "email") String email,
@RequestParam(value = "password") String password) {
....
@Configuration
@Import({JpaConfig.class,
BaseControlRestConfig.class,
AppInitializer.class})
@ComponentScan(basePackages = "com.roommate.basecontrol")
@EnableWebMvc
public class AppConfig {
}
@Configuration
@ComponentScan(value = "com.roommate.basecontrol.controllers.restControllers")
@Import({BaseControlServiceConfig.class,
BaseControlModelConfig.class})
public class BaseControlRestConfig {
@Bean
public RequestContextListener requestContextListener() {
return new RequestContextListener();
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question