Java 在SB应用程序中注释的顺序重要吗?
在我看来,注释的顺序不同会破坏我的构建 上面的答案是,一般来说,注释顺序应该无关紧要。就我而言,它正在破裂 这是公共模块 还有一个模块-高级计算 它将模块commons作为依赖项(maven依赖项) 请注意,这里有两个专门的maven模块。 因此,Java 在SB应用程序中注释的顺序重要吗?,java,spring,spring-boot,integration-testing,Java,Spring,Spring Boot,Integration Testing,在我看来,注释的顺序不同会破坏我的构建 上面的答案是,一般来说,注释顺序应该无关紧要。就我而言,它正在破裂 这是公共模块 还有一个模块-高级计算 它将模块commons作为依赖项(maven依赖项) 请注意,这里有两个专门的maven模块。 因此,CalculationController在使用commons依赖项的其他模块中可用 现在,让我在高级计算中做两个测试。(再次,我决定在另一个模块中测试CalculationController) 我知道最好是在模块中进行实际定义组件的测试,但是co
CalculationController
在使用commons依赖项的其他模块中可用
现在,让我在高级计算中做两个测试。(再次,我决定在另一个模块中测试CalculationController
)
我知道最好是在模块中进行实际定义组件的测试,但是commons模块是由其他团队很久以前编写的;现在我们必须使用它
我想确保如果我们更新了commons的版本,应用程序不应该中断(API不应该更改)。因此,我将CalculationController
的集成测试添加到高级计算模块中
@SpringBootTest(classes = [AdvancedCalculationApplication.class],properties = ["calculatorEnabled=true" ])
@AutoConfigureMockMvc
AdvancedCalculationsITTest extends Specification {
}
及
mvn清洁安装
失败,因为AdvancedCalculationsITTest
失败。错误无法自动连线CalculationController
,因为没有候选calculationService
然而,当我稍微改变注释的顺序时,它就起作用了
@ConditionalOnBean(CalculationService.class)
@RequestMapping(value = "/calculations", produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
class CalculationController {
}
我将更新此答案,但稍后会更新 我要做的事。 (我将制作一个演示,添加一个到github的链接,并提供一些代码示例) 欢迎您的意见和建议 我在一个方法上有两个自定义注释(运行时):一个注释使一个方法总是抛出异常
@exception
,另一个注释总是捕获异常@Catchable
。为了简单起见,让此方法返回void
。通过按不同的顺序放置这些注释,您应该会得到不同的结果
@Catchable
@Exceptional
public void processAction() {
// There is nothing that throws an exception.
safeStatement1();
safeStatement2();
safeStatementN();
}
vs
@SpringBootTest(classes = [AdvancedCalculationApplication.class],properties = ["calculatorEnabled=true" ])
@AutoConfigureMockMvc
AdvancedCalculationsITTest extends Specification {
}
@SpringBootTest(classes = [AdvancedCalculationApplication.class],properties = ["calculatorEnabled=" ])
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
@AutoConfigureMockMvc
AdvancedCalculationsITTestsDisabled extends Specification {
}
@ConditionalOnBean(CalculationService.class)
@RequestMapping(value = "/calculations", produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
class CalculationController {
}
@Catchable
@Exceptional
public void processAction() {
// There is nothing that throws an exception.
safeStatement1();
safeStatement2();
safeStatementN();
}
@Exceptional
@Catchable
public void processAction() {
// There is nothing that throws an exception.
safeStatement1();
safeStatement2();
safeStatementN();
}
By having these annotations in different order, the result should be different.