以下代码为正解!!! @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT ) public class TestLdap { @Autowired public LdapServiceImpl ldapService; @Value("${spring.ldap.fields}") public String fields; @Value("${spring.ldap.filter}") public String filter; @Test public void testUser(){ List<Map<String, Object>> users = ldapService.searchUsers(fields,filter); System.out.println(users.size()); } }
开始记录问题:
1.开始报找不到某个配置,因为读取的配置文件错了,开始我是这么配的@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT )
@ActiveProfiles("local")
public class TestJekins {
}
上面的local指读取application-local.yaml文件,而我的配置文件就是application.yaml文件,所以我把那段删掉了就好了
2.报javax.websocket.server.ServerContainer not available
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT )这样配置就好了