Tag : Spring

Spring Default Non-nested Calls The Spring Framework’s transaction infrastructure code will only identify transaction rollbacks by default when runtime and unchecked exceptions are thrown. That is, when an instance of a RuntimeException or its subclass is thrown. (Errors, too-by default-identifies transaction rollback. ) Checked exceptions thrown from the transaction method will not be identified for ..

Read more

ApplicationReadyEvent This event indicates that application should be initialized and ready to receive the request. Event published as late as conceivably possible to indicate that the application is ready to service requests. The source of the event is the SpringApp lication itself, but beware of modifying its internal state since all initialization steps will have ..

Read more

Order This article mainly talks about the differences between permitAll and webIgnore of spring security. PermitAll configuration instance @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override public void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers(“/css/**”, “/js/**”,”/fonts/**”).permitAll() .anyRequest().authenticated(); } } Web ignore configuration instance @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override public void configure(WebSecurity ..

Read more

Order This article mainly introduces the setting process of session timeout parameter value in spring boot. ServerProperties spring-boot-autoconfigure-1.5.8.RELEASE-sources.jar! /org/springframework/boot/autoconfigure/web/ServerProperties.java @Override public void customize(ConfigurableEmbeddedServletContainer container) { if (getPort() != null) { container.setPort(getPort()); } if (getAddress() != null) { container.setAddress(getAddress()); } if (getContextPath() != null) { container.setContextPath(getContextPath()); } if (getDisplayName() != null) { container.setDisplayName(getDisplayName()); } if (getSession().getTimeout() ..

Read more

Order Previously, I wrote an example of restTemplate. As spring 5 fully introduces reactive and also has restTemplate’s reactive version of webclient, this article will show the basic use of webclient correspondingly. Request to carry header Carry cookie @Test public void testWithCookie(){ Mono<String> resp = WebClient.create() .method(HttpMethod.GET) .uri(“http://baidu.com”) .cookie(“token”,”xxxx”) .cookie(“JSESSIONID”,”XXXX”) .retrieve() .bodyToMono(String.class); LOGGER.info(“result:{}”,resp.block()); } Carry ..

Read more

Order This article mainly describes the file upload and download of spring webflux. maven <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> File upload @PostMapping(value = “/upload”, consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public Mono<String> requestBodyFlux(@RequestPart(“file”) FilePart filePart) throws IOException { System.out.println(filePart.filename()); Path tempFile = Files.createTempFile(“test”, filePart.filename()); //NOTE 方法一 AsynchronousFileChannel channel = AsynchronousFileChannel.open(tempFile, StandardOpenOption.WRITE); DataBufferUtils.write(filePart.content(), channel, 0) .doOnComplete(() -> { System.out.println(“finish”); }) ..

Read more

Order This article mainly studies the EnableTransactionManagement of spring tx. EnableTransactionManagement spring-tx-5.1.6.RELEASE-sources.jar! /org/springframework/transaction/annotation/EnableTransactionManagement.java @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Import(TransactionManagementConfigurationSelector.class) public @interface EnableTransactionManagement { /** * Indicate whether subclass-based (CGLIB) proxies are to be created ({@code true}) as * opposed to standard Java interface-based proxies ({@code false}). The default is * {@code false}. <strong>Applicable only if {@link #mode()} ..

Read more

Problem description Business requirements need to be based on a certain field value, assuming the value isdemo(This value is unique) to create a file nameddemoCollection of. After that, the document information related to demo (the structure is fixed) will be stored in this collection. The environmental background of the problem and what methods have you ..

Read more

For the same query, using mongoTemplate will be much slower. using mongodb tool, the execution plan will be very fast, and the difference is very big. It seems that your two screenshots do not execute a query (at least the second screenshot has sort and the first Java code does not). Since this is not ..

Read more

Why is mongoTemplate always null?springmvc mongo intellij idea macosThe error message is java.lang.NullPointerExceptionHello, great godsI’m building an APP backstage with itellij idea on MacOS. Now I need to integrate mongo. I’m having a problem. Is mongoTemplate always null every time a request is made to access the background interface?Some kind-hearted people please help me and ..

Read more

After Mongodb connection times out, the first database query for reconnection will fail, and it is normal to connect again, which is always the case after each timeout. Just look at the problem description and don’t see anything, just post the key code directly. It is possible that mongo did not replace the old variable ..

Read more

I am now making a small demo through spring-boot+spring-mongo, which is the latest version. Now there is a problem that I cannot connect to other libraries in any way, only mongodb’s default test library. What is the reason? Yml: spring.data.mongodb.uri: mongodb://localhost:27017/mongo In theory, this should be connected to the mongo library. My mongodb does not ..

Read more