Java 使用SpringMVC在方法级别创建Spring概要文件 @RestController @请求映射(value=“/develop”) @配置 公共类开发控制器{ @资源(name=“smsService”) 私人SmsService SmsService; @RequestMapping(value=“/verification/selectAuthVerifyCode”,method=RequestMethod.GET,products=Constant.APP\u JSON) @豆子 @配置文件({“本地”}) public@ResponseBody authverifycode选择authverifycode( @RequestParam(value=“callingCode”,required=true)字符串callingCode ,@RequestParam(value=“regionPhoneNumber”,required=true)字符串regionPhoneNumber )抛出异常{ AuthVerifyCodeO结果=新的AuthVerifyCodeO(); 结果=SMS服务。选择AuthVerifyCode(callingCode,regionPhoneNumber); 返回结果; } }
我想在方法级别上使用Java 使用SpringMVC在方法级别创建Spring概要文件 @RestController @请求映射(value=“/develop”) @配置 公共类开发控制器{ @资源(name=“smsService”) 私人SmsService SmsService; @RequestMapping(value=“/verification/selectAuthVerifyCode”,method=RequestMethod.GET,products=Constant.APP\u JSON) @豆子 @配置文件({“本地”}) public@ResponseBody authverifycode选择authverifycode( @RequestParam(value=“callingCode”,required=true)字符串callingCode ,@RequestParam(value=“regionPhoneNumber”,required=true)字符串regionPhoneNumber )抛出异常{ AuthVerifyCodeO结果=新的AuthVerifyCodeO(); 结果=SMS服务。选择AuthVerifyCode(callingCode,regionPhoneNumber); 返回结果; } },java,spring,spring-boot,Java,Spring,Spring Boot,我想在方法级别上使用@Profile,但发生错误 如何解决此问题?我假设您没有使用Spring上下文设置概要文件。您需要在执行上下文中添加以下内容 @Autowired private ConfigurableEnvironment env; env.setActiveProfiles("local"); 我已经设置了Tomcat启动配置-Dspring.profiles.active=local@JungGa启动日志显示它执行时所采用的配置文件。验证是local1还是de
@Profile
,但发生错误
如何解决此问题?我假设您没有使用Spring上下文设置概要文件。您需要在执行上下文中添加以下内容
@Autowired
private ConfigurableEnvironment env;
env.setActiveProfiles("local");
我已经设置了Tomcat启动配置-Dspring.profiles.active=local@JungGa启动日志显示它执行时所采用的配置文件。验证是
local1
还是default
?2020-12-10 15:59:08.352信息49192---[ost-startStop-1]c.l.context.config.ServletConfigurator:以下配置文件处于活动状态:local@JungGa,看起来您添加了其他详细信息和相关代码。请参阅M.Deinum的评论。他说得很有道理。那种方法没有道理。为什么它既是一个@Bean
方法又是一个控制器方法。那没有道理。这也是一个@configuration
和@RestController
的事实。您可以尝试删除花括号-@Profile(“local”)?花括号没关系,我必须使用@RestControlleri removed@configuration和@Bean注释,这可能吗?
@Autowired
private ConfigurableEnvironment env;
env.setActiveProfiles("local");