我使用Spring Starter项目模板在Eclipse中创建了一个项目.
它自动创建了一个Application类文件,该路径与POM.xml文件中的路径匹配,所以一切都很好.这是Application类:
@Configuration
@ComponentScan
@EnableAutoConfiguration
public class Application {
public static void main(String[] args) {
//SpringApplication.run(ReconTool.class, args);
ReconTool.main(args);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我正在构建的命令行应用程序,为了让它运行我必须注释掉SpringApplication.run行,只需从我的其他类中添加main方法即可运行.除了这个快速的jerry-rig之外,我可以使用Maven构建它,它可以作为Spring应用程序运行.
但是,我宁愿不必注释掉那一行,并使用完整的Spring框架.我怎样才能做到这一点?
我的带@ControllerAdvice注释的控制器看起来像这样:
@ControllerAdvice
public class GlobalControllerExceptionHandler {
@ResponseStatus(value = HttpStatus.UNAUTHORIZED)
@ExceptionHandler(AuthenticationException.class)
public void authenticationExceptionHandler() {
}
}
Run Code Online (Sandbox Code Playgroud)
当然我的开发是测试驱动的,我想在JUnit测试中使用我的异常处理程序.我的测试用例如下所示:
public class ClientQueriesControllerTest {
private MockMvc mockMvc;
@InjectMocks
private ClientQueriesController controller;
@Mock
private AuthenticationService authenticationService;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mockMvc = MockMvcBuilders.standaloneSetup(controller).build();
}
@Test
public void findAllAccountRelatedClientsUnauthorized() throws Exception {
when(authenticationService.validateAuthorization(anyString())).thenThrow(AuthenticationException.class);
mockMvc.perform(get("/rest/clients").header("Authorization", UUID.randomUUID().toString()))
.andExpect(status().isUnauthorized());
}
}
Run Code Online (Sandbox Code Playgroud)
可能我需要注册ControllerAdvice课程.怎么做?
当我在 Quarkus 应用程序中使用类似以下内容时:
@Path("v1")
@Produces(APPLICATION_JSON)
public class HelloWorldResource {
@Inject
private SomeBean someBean;
}
Run Code Online (Sandbox Code Playgroud)
然后我在构建过程中收到以下警告。
[INFO] [io.quarkus.arc.processor.BeanProcessor] Found unrecommended usage of private members (use package-private instead) in application beans:
- @Inject field acme.jaxrs.v1.HelloWorldResource#someBean
Run Code Online (Sandbox Code Playgroud)
一切似乎都很好,那么为什么 Quarkus 建议更改private为package-private?
我想覆盖我在Quarkus应用程序的配置文件中配置的属性。
我怎样才能做到这一点?
我想设置一个基本路径,我的所有 RESTEasy 资源都将落在该路径下,而不必包含扩展的类javax.ws.rs.core.Application。
基本上我想摆脱:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("/api")
public class MyApplication extends Application {
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我想要的是一个if-else in th:Thymeleaf中的每个陈述.
If currentSkill != null,然后显示包含内容的表格,否则'你没有任何技能'
这是没有if/else的代码:
<div th:each="skill : ${currentSkills}">
<table>
<tr><td th:text="${skill.name}"/></tr>
</table>
</div>
Run Code Online (Sandbox Code Playgroud) 当我们在spring中定义任何组件的配置文件时,我们将其声明为
@Profile(value="Prod").但我想从属性文件中提供该值.可能吗?如果有,怎么样?
当我运行 Quarkus 应用程序时,它仅默认侦听/绑定到 localhost。
我怎样才能改变这种行为?
我有一个 CDI bean,如下所示:
@Dependent
class Parser {
String[] parse(String expression) {
return expression.split("::");
}
}
Run Code Online (Sandbox Code Playgroud)
它被注入到另一个 bean 中,如下所示:
@ApplicationScoped
class ParserService {
@Inject
Parser parser;
//...
}
Run Code Online (Sandbox Code Playgroud)
我想做的是继续Parser在我的常规代码中使用,但我想使用“模拟”来进行测试。我怎样才能做到这一点?
quarkus ×6
spring ×3
java ×2
spring-boot ×2
spring-mvc ×2
eclipse ×1
junit ×1
mockmvc ×1
thymeleaf ×1