我已经以经典方式在Spring Security控制器中设置了基本身份验证,如下所示:
@EnableWebSecurity
@EnableGlobalMethodSecurity
public class MySecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user").password("user").roles("USER")
.and()
.withUser("admin").password("admin").roles("USER", "ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers(....);
}
}
Run Code Online (Sandbox Code Playgroud)
说到测试点,我正在使用@WithMockUser注释我的测试。GET的测试可能如下所示:
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = SomeController.class)
public class SomeControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void test1() {
mockMvc.perform(get(...)).andExpect(...);
}
Run Code Online (Sandbox Code Playgroud)
或像这样的POST:
@RunWith(SpringRunner.class)
@WebMvcTest(controllers = SomeController.class)
public class SomeControllerTest {
@Autowired
private MockMvc mockMvc;
@Test
public void test1() {
mockMvc.perform(post(...)).andExpect(...);
}
Run Code Online (Sandbox Code Playgroud)
然后发生了意外情况:
我在考虑目标令牌的同时逐行解析.txt.我使用正则表达式处理器引擎.
我匹配每一行:
"(^|.*[\\s])"+token+"([\\s].*|$)"
Run Code Online (Sandbox Code Playgroud)
其中token是一个字符串.什么时候:
token="6-7(3-7"
Run Code Online (Sandbox Code Playgroud)
它产生以下例外:
Exception in thread "main" java.util.regex.PatternSyntaxException:
Unclosed group near index 27
(^|.*[\s])6-7(3-7([\s].*|$)
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
在测试类中,当我们指示mockito提供一些模拟对象(用标记这样的属性字段@Mock)(例如,将其注入@InjectMocks属性字段)时,创建每个模拟对象遵循的规则是什么?
进一步来说:
1)每个模拟是如何构建的?
2)如何处理每个模拟的依赖关系?模拟时应考虑哪些规则和限制?
3)“模拟的类A依赖于类B,而类B又被模拟(在同一测试类中)”的情况与“模拟的A类依赖于类B而类B不被模拟”的情况不同吗?
考虑Java 的简单日志外观 (SLF4J) 。作为背景,它通过简单的外观模式提供 API ,通过将所需的绑定添加到类路径来在运行时确定底层日志记录后端。它可能是标准的java.util.logging、log4j、logback或tinylog。
客户端应用程序与日志记录后端的巧妙分离减少了特定应用程序与任何特定日志记录框架之间的耦合。这可以更轻松地将新实现的客户端与已选择日志记录后端的其他项目的现有代码集成。
因此,考虑到日志记录 API SLF4J,对于编译,您只需要slf4j-api,并且应避免将任何特定绑定(如slf4j-log4j12)包含为编译依赖项。
因此,slf4j-log4j12是运行时范围依赖项(而不是编译依赖项)的良好候选者,因为这将允许您在运行时在slf4j 绑定之间切换,而无需重新编译应用程序。
之间有什么区别scm:tag:
<scm>
<connection>scm:git:code.stuff.com/scm/project/repo.git</connection>
<developerConnection>scm:git:ssh://git@code.stuff.com:7999/project/repo.git</developerConnection>
<tag>HEAD</tag>
</scm>
Run Code Online (Sandbox Code Playgroud)
我读到,在release:prepare目标过程中,系统会提示用户输入要粘贴的所需标签名称;准备工作成功完成后,Maven 将使用传递的名称在 VCS 中标记发布候选版本。此时,还有什么用呢scm:tag?
Tomcat是servlet容器.Docker是一个"容器".
他们做什么类似被称为两个容器?他们在哪里差异最大?
我在Windows操作系统下开发了一个正确处理Eclipse的Java项目.然后我想切换到Ubuntu.我刚刚从Windows获取了完整的工作区文件夹(包括运行所需的所有资源文件),并将其导入Ubuntu的Eclipse中.
最令人惊讶的是我得到以下异常:
[ Test ] ERROR: unable to create myClass object.
Check your implementation requirements!
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at Test.main(Test.java:183)
Caused by: java.io.FileNotFoundException: raw\file1.txt (No such file or directory)
...
Run Code Online (Sandbox Code Playgroud)
但是这样的目录和这样的文件确实存在于当前路径中.
为什么会这样?
在C++中,以下是合法的:
template <int i>
run(){...}
run<3>(); // legal
const int j=3;
run<j>(); // legal because j is const
Run Code Online (Sandbox Code Playgroud)
为什么以下是合法的还是不合法的?
template <String s>
run(){...}
run<"hello">(); // legal or illegal?
const string s="hello";
run<s>(); // legal or illegal?
Run Code Online (Sandbox Code Playgroud) java ×3
maven ×2
apache ×1
c++ ×1
containers ×1
docker ×1
linux ×1
maven-scm ×1
mocking ×1
mockito ×1
regex ×1
slf4j ×1
spring ×1
spring-boot ×1
spring-data ×1
spring-mvc ×1
tomcat ×1
windows ×1