0
@RestController
@RequestMapping(value = "/develop")
@Configuration
public class DevelopController {
    
    @Resource(name = "smsService")
    private SmsService smsService;

@RequestMapping(value = "/verification/selectAuthVerifyCode", method = RequestMethod.GET, produces = Constant.APP_JSON)
    @Bean
    @Profile({"local"})
    public @ResponseBody AuthVerifyCodeO selectAuthVerifyCode(
              @RequestParam(value="callingCode", required=true) String callingCode
          ,  @RequestParam(value="regionPhoneNumber", required=true) String regionPhoneNumber
            ) throws Exception {
        
        AuthVerifyCodeO result = new AuthVerifyCodeO();
        
        result = smsService.selectAuthVerifyCode(callingCode, regionPhoneNumber);
            
        return result;
    } 
}

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'selectAuthVerifyCode' defined in class path resource [com/test/scheduler/executor/DevelopController.class]: Unsatisfied dependency expressed through method 'selectAuthVerifyCode' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.lang.String' available: expected at least 1 bean which qualifies as autowire candidate

我想@Profile在方法级别上使用但发生错误我该如何解决这个问题?

4

1 回答 1

1

我假设,您没有使用 Spring 上下文设置配置文件。您需要在执行上下文中添加以下内容。

@Autowired
private ConfigurableEnvironment env;
env.setActiveProfiles("local");
于 2020-12-10T06:37:47.580 回答