我有以下代码,并希望使用lambda函数实现它只是为了好玩.可以使用基本的聚合操作吗?
List<Integer> result = new ArrayList<>();
for (int i = 1; i <= 10; i++) {
if (10 % i == 0) {
result.add(i);
if (i != 5) {
result.add(10 / i);
}
}
}
Run Code Online (Sandbox Code Playgroud)
使用lambda:
List<Integer> result = IntStream.rangeClosed(1, 10)
.boxed()
.filter(i -> 10 % i == 0)
// a map or forEach function here?
// .map(return 10 / i -> if i != 5)
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud) 当我启动springboot应用程序时,我的SpringBootLoginController类抛出此错误(无法启动嵌入式容器),如下所示.它是一个hello world类型的spring启动应用程序示例.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.5.2.RELEASE)
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.context.ApplicationContextException: Unable to start …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 Spring Security 来连接 LDAP,但它总是显示错误的凭据问题。
我想我的代码可能有问题:
@Configuration\n@EnableWebSecurity\n@EnableGlobalMethodSecurity(prePostEnabled = true)\npublic class SecurityConfig extends WebSecurityConfigurerAdapter {\n @Override\n public void configure(WebSecurity web) throws Exception {\n web.debug(true);\n }\n @Autowired\n public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {\n\n auth.ldapAuthentication().userDnPatterns("sAMAccountName={0},OU=SupportUsers,OU=Users,OU=company,DC=ad,DC=company,DC=com,DC=pl")\n .contextSource(contextSource()).passwordCompare().passwordAttribute("userPassword");\n }\n protected void configure(HttpSecurity http) throws Exception {\n http\n .authorizeRequests()\n .anyRequest().fullyAuthenticated()\n .and()\n .formLogin();\n http.csrf().disable(); //Vaadin already have built in csrf\n }\n @Bean\n public LdapContextSource contextSource () {\n LdapContextSource contextSource= new LdapContextSource();\n contextSource.setUrl("ldap://192.168.2.2:389");\n contextSource.setBase("dc=ad,dc=company,dc=com,dc=pl");\n contextSource.setUserDn("CN=lister,OU=SupportUsers,OU=Users,OU=company,DC=ad,DC=company,DC=com,DC=pl");\n contextSource.setPassword("examplePassword");\n contextSource.setAnonymousReadOnly(false);\n contextSource.setPooled(true);\n contextSource.afterPropertiesSet();\n return contextSource;\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n我在代码中找不到错误,也许我做错了事情。这是我的 pom.xml:
\n\n …