New answers tagged spring
0 votes
Spring Boot Flyway not running on startup
To me there is an issue with the spring-boot-dependencies (as part of spring-boot-starter-parent 4.0.4). In the spring-boot-dependencies, you'll see two flavors of flyway-dependencies are included: ...
1 vote
How to correctly map nested OpenID Connect (OIDC) claims to Spring Security 6 Authorities?
I'm configuring the SecurityFilterChain like the following in one of my projects: @Bean public SecurityFilterChain securityFilterChain( final HttpSecurity http, final ...
0 votes
Dynamic route for LoginPage in security configuration
This may work for your case: Use a custom LoginUrlAuthenticationEntryPoint instance: public class LocaleLoginUrlAuthenticationEntryPoint extends LoginUrlAuthenticationEntryPoint { private final ...
Advice
0 votes
0 replies
0 views
Is Spring framework 6.x compatible with Spring Security 7.x?
But, in the docs (reference), it says that: Spring Security builds against Spring Framework 7.0.6 but should generally work with any newer version of Spring Framework 5.x.*.
Advice
0 votes
0 replies
0 views
Is Spring framework 6.x compatible with Spring Security 7.x?
Spring Framework 7 and Spring Security 7 both require Jakarta EE 11, which depends on Servlet 6.1 and updated APIs (like JPA 3.2). Spring Framework 6.x, on the other hand, is based on Jakarta EE 9/10 ...
Advice
0 votes
0 replies
0 views
Is Spring framework 6.x compatible with Spring Security 7.x?
Spring Framework 7 and Spring Security 7 require Jakarta EE 11. This means they rely on Servlet 6.1 (and other updated APIs like JPA 3.2). Spring Framework 6.x is based on Jakarta EE 9/10 (Servlet 5.0/...
Best practices
0 votes
0 replies
0 views
Where to put linkTo method in Spring?
Dev-B is correct because centralizing all link-building logic, including "self" links, in a dedicated Assembler class adheres strictly to the Single Responsibility Principle and promotes a ...
0 votes
Spring Boot 4.0.0 + GCP : java.lang.NoSuchMethodError: org.springframework.boot.context.config.ConfigDataLocationResolverContext.getBootstrapContext()
This works with Spring Boot 4.0.3: <dependencyManagement> <dependencies> <dependency> <groupId>com.google.cloud</groupId> <...
Tooling
0 votes
0 replies
0 views
Spring gRPC and Spring Boot compatibility
No, it's not backwards compatible. A lot of it will work, but not everything. You should use Spring Boot 4 with it.
Advice
0 votes
0 replies
0 views
Design billing system microservices communication
In addition, when I used to do billing, it was a simple call service judgment at the beginning, but I think it would be better to use the interceptor at the gateway layer to be more flexible
Advice
0 votes
0 replies
0 views
Design billing system microservices communication
I think the problem is that a service needs to provide data for a page and another service, but you don't know if it should be combined into the same API. I think it should be separated, because the ...
0 votes
Grpc client with channel whose name is derived from the stub class
I've managed to achieve this by extending the GrpcClientFactory and registering to replace the default one. I was hoping there would be a simpler way to do it, but as Max says in his answer, it seems ...
1 vote
Grpc client with channel whose name is derived from the stub class
The official Spring gRPC (and most third-party starters) purposely avoids automagically deriving channel names from class names to keep your infrastructure configuration (the channel) decoupled from ...
0 votes
Spring AOP @Pointcut not triggering
If used correctly, there is a special situation where AOP will fail. Make sure that when you call the getOrg() method, the instance you use is a bean registered with spring, not nested calls in ...
0 votes
Spring Boot graphQl autoconfiguration fails to instantiate graphQlSource at app startup
Ran into the same problem today. Found out that the fields in my class were private and graphql requires public fields to be mapped to its schema.
2 votes
VectorStore.accept() exhausts HikariCP connection pool when batch ingesting with virtual threads
The core issue is that virtual threads remove the natural backpressure that platform threads provide. With a FixedThreadPool(10), you'd never have more than 10 concurrent accept() calls. With virtual ...
0 votes
Spring Security OAuth2 Authorization Server to support Device Authorization Flow with public clients using ClientAuthenticationMethod.NONE
There was a ticket about adding a sample for this exact use-case. The ticket is closed, and the result is to be seen in the demo-authorizationserver sample directory. Long story short, There is a ...
0 votes
Parallel Spring Batch jobs mixing up data
The issue is a race condition in your loop. When you use files[i], the rapid iteration of the thread pool causes multiple threads to grab the same index value before the next iteration completes. // ...
0 votes
How to get method name in spring filter
For what it's worth but I have used the following (using spring 3.4.4): @Component public class TestFilter extends OncePerRequestFilter { private final GenericApplicationContext applicationContext;...
0 votes
Connection refused when connecting to host mysql db from docker container
Try out these. It worked for me in Windows Step 1 Press the Windows Key on your keyboard, type Windows Defender Firewall with Advanced Security, and press Enter. In the left-hand panel, click on ...
Advice
0 votes
0 replies
0 views
Any product to show ROI on code refactoring or improvements
How would a tool know what “technical debt” looks like in your specific context? How would ROI be calculated?
0 votes
How to use a jsonb column with H2, JPA, and Hibernate
This solution worked for me : Add hypersistence-utils-hibernate in the dependencies : <dependency> <groupId>io.hypersistence</groupId> <artifactId>...
0 votes
Spring WebFlux + Spring AI + OpenRouter: "block()/blockFirst()/blockLast() are blocking" error in coroutine
You can use the streaming API exposed by SpringAI that usually returns a Flux which you can align it with your coroutines without any blocking. Sample Controller for SSE: @GetMapping("/chat",...
Advice
0 votes
0 replies
0 views
Any product to show ROI on code refactoring or improvements
Tools can't do that, because tools can't measure if you are feeling pain and are thinking about updating your resume to go apply for another job. Technical debt is a label, not a programming paradigm. ...
0 votes
Spring Boot ConfigurationPropertiesBinding for ImmutableMap
Spring Boot's Environment flattens map properties (e.g., test.map-property.foo=1). Because there is no single "Map" object in the source environment to pass to your Converter, Spring Boot ...
Advice
0 votes
0 replies
0 views
Any product to show ROI on code refactoring or improvements
@MartinBrown it may be valid to make recommendations for open ended questions. Not sure of the guidelines for open ended questions. But the question is not actually related to programming. It is more ...
Advice
0 votes
0 replies
0 views
Any product to show ROI on code refactoring or improvements
Recommendations are off topic here. McCabe's CCI isn't a bad way to find code in a large codebase that is so convoluted and opaque that it must be hiding bugs. But deciding on which bugs to fix for ...
Advice
0 votes
0 replies
0 views
Any product to show ROI on code refactoring or improvements
What makes you think such a tool exists anywhere?
0 votes
Accepted
Prevent Google Authentication when using spring.cloud.gcp.pubsub with emulator (locally)
Thanks all for your help, apologize that I did not updated the outcome. Within the application another manually written PubSub library was used, that was not using spring, but google-cloud-pubsub. So ...
Tooling
1 vote
0 replies
0 views
Spring boot structured logging issue
Extend EcsStructuredLogFormatter directly This is the correct fix. Override the service-writing logic to include service.id: public class CustomEcsFormatter extends EcsStructuredLogFormatter { ...
0 votes
Spring AI support of enumNames
For tool/function inputs Spring AI generates only standard JSON schema. You can try using oneOf in combination with const and title instead of the usual enum pattern. "myEnum": { "...
0 votes
Spring AI and Spring Cloud Compatibility Issue: JSON Parsing Error in OpenAI Chat Client
You can try below workarounds as well. 1.Combining Spring Cloud 4.2.x with Spring AI M6 may cause HTTP client conflicts. If you are allowed to upgrade the Spring AI version, then changing to 1.0.0 ...
0 votes
Spring-core 7 does not support ExceptionCauseClassifierRetryPolicy
Instead of using a dedicated classifier policy, you should use the standard SimpleRetryPolicy and enable the traverseCauses flag. This allows the policy to look down the exception stack trace to find ...
0 votes
Prevent Google Authentication when using spring.cloud.gcp.pubsub with emulator (locally)
When using Spring you can provide a NoCredentialsProvider Bean, which tells the Google Cloud Library that no authentication was done. @Configuration class PubsubEmulatorConfig { @Bean fun ...
0 votes
Spring Boot - Error creating bean with name 'dataSource' defined in class path resource
This happened to me. Problem, was @Autowired private ConfigurableApplicationContext context; context.close() And, while running database activities in Background thread. So, the database connections ...
Best practices
0 votes
0 replies
0 views
Is it safe to reuse UserDetails from SecurityContext instead of querying the database again?
It is safe to reuse the UserDetails from the SecurityContext because the user information has already been loaded from the database and is considered valid for the duration of the request. ...
0 votes
Springfox - Swagger UI - "Unable to infer base url...or when the API is behind an API Gateway" - error with ipv6 host, for ipv4 swaggerui works fine
Don’t use Springfox Swagger UI; use SpringDoc OpenAPI Starter WebMVC UI instead, it’s better and won’t crash. <dependency> <groupId>org.springdoc</groupId> <artifactId>...
1 vote
Graceful shutdown of SimpleAsyncTaskExecutor
An issue #36362 has been submitted to Spring Framework and it was resolved by Juergen Hoeller with commit 728466d. The source code of SimpleAsyncTaskExecutor, corresponding to this commit, has been ...
0 votes
MongoDb mongoTemplate for multiple databases
Another solution can be something like this import com.mongodb.client.MongoClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.mongodb....
0 votes
@WebMvcTest behaviour related to security is different in Spring Boot 4.x compared to Spring Boot 3.x
Including spring-boot-starter-security-test will eventually pull in the spring-boot-security-test module. This module contains all test auto-configuration for the security part. Specifically for ...
1 vote
MongoDb mongoTemplate for multiple databases
To handle multiple databases, you need to define two separate MongoTemplate beans and instruct your repositories (or manual calls) which one to use. @Configuration public class MongoConfig { @...
-1 votes
@WebMvcTest behaviour related to security is different in Spring Boot 4.x compared to Spring Boot 3.x
The issue occurs because @WebMvcTest is a sliced test that scans for Spring MVC infrastructure but does not automatically pull in your custom @Configuration classes where security rules (like ...
Advice
0 votes
0 replies
0 views
Design billing system microservices communication
Post updated. But if I don't have a API calls to get data between microservices the alternative will be to have a shared database which is also not good?
Advice
0 votes
0 replies
0 views
Design billing system microservices communication
Please clarify the meaning of public API and private API. But in general, service 1 should provide an API to get all required data for whatever serivce 2 is doing. In other words, avoid chatty ...
0 votes
Spring data jdbc and child entity equality
A lot of things are removed in videos for simplicities. Just like we removed the business logic in entities for Hibernate example on the internet, people thought entities were no place to put business ...
1 vote
@Pattern and @NotBlank on password field still triggered even when password is null, validation groups cause MapStruct mapping issues
Force the validator to stop after the first failure. By using @GroupSequence, if @NotBlank fails, the validation engine won't even look at the @Pattern. @GroupSequence({Required.class, Format.class, ...
0 votes
SpringBoot - BeanDefinitionOverrideException: Invalid bean definition
I had the same issue, just with different bean definition name: conventionErrorViewResolver. In my case, it was using 3.X.X version of springdoc-openapi-start-webmvc-ui artifact with spring boot ...
1 vote
What is the difference between transaction isolation levels and optimistic/pessimistic concurrency control?
This is one of those topics where the terminology can get really blurry because they both deal with "concurrency," but they operate at different layers. To keep it simple: Isolation Levels ...
Best practices
0 votes
0 replies
0 views
Should I implement UserDetails directly in my User entity or create a separate UserPrincipal class in Spring Security?
Nope. I am suggesting to not use plurals in database table names. Also, trying to label a discussion as "off-topic" in order to suppress it because you don't like the subject is pretty lame.
2 votes
What is the difference between transaction isolation levels and optimistic/pessimistic concurrency control?
Are transaction isolation levels and optimistic/pessimistic concurrency control fundamentally different concepts? Yes. isolation levels make sense from the perspective of the user of the DB, whereas ...
Top 50 recent answers are included
Related Tags
spring × 213890java × 130801
spring-boot × 55073
spring-mvc × 34204
hibernate × 23954
spring-security × 15102
jpa × 11577
spring-data-jpa × 9289
maven × 8678
rest × 7376
spring-data × 5761
tomcat × 4919
jsp × 4856
json × 4461
mysql × 4297
spring-batch × 4266
thymeleaf × 3649
spring-integration × 3449
junit × 3445
mongodb × 3265
dependency-injection × 2766
transactions × 2681
xml × 2538
jackson × 2535
javascript × 2493