我使用spring boot version"1.3.0.M5"(我也试过版本"1.2.5.RELEASE").我添加了弹簧安全性:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
和代码:
@SpringBootApplication
public class SpringBootMainApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootMainApplication.class, args);
}
}
@Configuration
@EnableWebSecurity
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("password").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/api/sampleentity").authenticated()
.and().authorizeRequests()
.and().formLogin().permitAll()
.and().logout().permitAll().logoutUrl("/logout")
.logoutSuccessUrl("/");
}
@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
@RestController
@RequestMapping("/api/sampleentity")
public class SampleEntityController {
@RequestMapping(method= …
Run Code Online (Sandbox Code Playgroud) 我想从 PostgreSQL 11.2 流式传输结果,而不是一次将所有结果读取到内存中。我使用最新的稳定版 SpringBoot 2.1.4.RELEASE。
我阅读了如何在 MySQL 中执行此操作的文章。 http://knes1.github.io/blog/2015/2015-10-19-streaming-mysql-results-using-java8-streams-and-spring-data.html 我还阅读了如何在 PostgreSQL 中执行此操作的文章: Postgresql 中的 Java 8 JPA 存储库流逐行
我有这样的存储库:
public interface ProductRepository extends JpaRepository<Product, UUID> {
@Query("SELECT p from Product p")
@QueryHints(value = @QueryHint(name = HINT_FETCH_SIZE, value = "50"))
Stream<Product> streamAll();
}
Run Code Online (Sandbox Code Playgroud)
比我这样使用流:
productRepository.streamAll().forEach(product -> export(product));
Run Code Online (Sandbox Code Playgroud)
为了使示例更简单,'export' 方法完全为空。
当我调用该方法时,我看到 Hibernate 查询
Hibernate: select product0_.id as id1_0_, product0_.created as created2_0_, product0_.description as descript3_0_, product0_.name as name4_0_, product0_.product_type_id as product_5_0_ from products product0_ order by product0_.id
Run Code Online (Sandbox Code Playgroud)
一段时间后,我出现了 OutOfMemoryError。查询提示没有帮助。
如何使用 Spring Boot …
我想在我的Spring Boot 4应用程序中添加缓存.作为一个键,我想使用我的实体的id(类型Long),值是我的实体.
@EnableCaching
@SpringBootApplication
public class SpringBootMainApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootMainApplication.class, args);
}
}
@Configuration
public class AppConfiguration {
@Bean
public CacheManager cacheManager() {
return new ConcurrentMapCacheManager("findOne");
}
}
public interface SampleEntityService extends CrudRepository<SampleEntity, Long> {
@Cacheable(key = "#a0", value = "findOne")
SampleEntity findOne(Long id);
Run Code Online (Sandbox Code Playgroud)
但是当我在测试中调用findOne方法时,我得到了一个异常:
java.lang.ClassCastException: org.springframework.cache.support.SimpleValueWrapper cannot be cast to my.springboot.model.SampleEntity
at my.springboot.SampleEntityCacheTest.aaa(SampleEntityCacheTest.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:73)
at …
Run Code Online (Sandbox Code Playgroud) 在AWS lambda函数(用Java编写)中我想使用AsyncHttpClient(https://github.com/AsyncHttpClient/async-http-client). Unfortunately it takes around 500 ms to create an instance of this object.. (but I still like it, please don't advice me to change the http client).
我正在考虑在静态初始化块中创建 AsyncHttpClient 。因此,它可能会由 AWS 执行一次,并且每次 AWS Lambda 执行都会克隆快照。我对么 ?
何时在 AWS Lambda 中执行静态块?
谢谢你的帮助
java ×4
spring-boot ×3
spring ×2
aws-lambda ×1
caching ×1
java-8 ×1
jpa ×1
postgresql ×1
spring-mvc ×1