在Spring Data JPA文档中它说的关于流:
Stream可能会包装底层数据存储特定资源,因此必须在使用后关闭.您可以使用close()方法手动关闭Stream,也可以使用Java 7 try-with-resources块.
请参阅:http://docs.spring.io/spring-data/jpa/docs/1.10.1.RELEASE/reference/html/#repositories.query-streaming
如果我使用forEach,计数或其他终端操作处理流,它应该已经关闭(并且不能再次重复使用),我不必将流包装在额外的try-resources-block中(假设我的块没有'扔任何异常),或者我错在这里?
我有这个属性类:
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties("some")
public class SomeProperties {
private List<String> stuff;
public List<String> getStuff() {
return stuff;
}
public void setStuff(List<String> stuff) {
this.stuff = stuff;
}
}
Run Code Online (Sandbox Code Playgroud)
我在 @Configuration 类中启用配置属性,如下所示:
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties(SomeProperties.class)
public class SomeAutoConfiguration {
}
Run Code Online (Sandbox Code Playgroud)
在同一个类(“SomeAutoConfiguration”)中,我想根据 SomeProperties 中的列表属性是否为空来创建另一个 bean。我想我可以将@ConditionalExpression 与以下 SpEl 一起使用:
@Bean
@ConditionalOnExpression("!(#someProperties.stuff?.isEmpty()?:true)")
public Object someBean(final SomeProperties someProperties) {
return new Object();
}
Run Code Online (Sandbox Code Playgroud)
SpEl 是正确的,但我无法获得包含我的属性的 bean。使用上面的表达式我遇到了
EL1007E:(pos 43): 在 null 上找不到属性或字段“东西”
并试图通过它的名字来获取豆子
@Bean
@ConditionalOnExpression("!(@'some.CONFIGURATION_PROPERTIES'.stuff?.isEmpty()?:true)")
public Object someBean(final SomeProperties someProperties) { …Run Code Online (Sandbox Code Playgroud)