我在不同的软件包中使用多个控制器,但在启动我的启动应用程序时,它让我开始失败:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.xyz.UserIntegrationServiceApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'userController' for bean class [com.xyz.a.UserController] conflicts with existing, non-compatible bean definition of same name and class [com.xyz.b.UserController]
@SpringBootApplication
public class UserIntegrationServiceApplication {
public static void main(String[] args) {
SpringApplication.run(UserIntegrationServiceApplication.class, args);
}
}
@RestController
@RequestMapping("/api/")
public class UserController {
public static final Logger logger = LoggerFactory.getLogger(UserController.class);
@Autowired
UserService userService;
@RequestMapping(value = "/di/user", method = RequestMethod.POST, consumes = {MediaType.APPLICATION_JSON_VALUE}, produces = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity<?> createUser(@RequestBody(required = true) User user, @RequestHeader(required = true, value = HttpHeaders.AUTHORIZATION) String authorization) {
return userService.createUser(user,authorization);
}
}
}
@RestController
@RequestMapping("/api/")
public class UserController {
public static final Logger logger = LoggerFactory.getLogger(UserController.class);
@Autowired
UserService userService;
@RequestMapping(value = "/ds/user", method = RequestMethod.POST, consumes = {
MediaType.APPLICATION_JSON_VALUE }, produces = { MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<?> loginUser(@RequestBody(required = true) LoginRequest login,
@RequestHeader HttpHeaders headers) {
return userService.loginUser(login, headers);
}
}
###########请帮我解决这个问题
答案 0 :(得分:0)
您只需要为两个UserController设置不同的bean名称。