802 questions
Best practices
2
votes
2
replies
127
views
How to make a bean initialize before DataSource without excluding auto‑configuration
I have a Spring Boot application that relies on the default DataSourceAutoConfiguration to create my DataSource bean. I also have a custom bean that must be fully initialized before the DataSource ...
2
votes
2
answers
148
views
Autowire multiple beans into a Map
I’m working on a Spring Boot application where I have multiple implementations of a service interface, and I want to automatically wire them into a Map keyed by an enum type.
Specifically, I have a ...
-2
votes
1
answer
613
views
Can i use spring version 6 and above with Java version 8?
I wanted to upgrade my spring version from 5.3.39 to the 6 series. But when I tried to do that, it didn't compile and threw an error.
This is the error that I'm getting:
Failed to execute goal org....
0
votes
0
answers
51
views
How to dynamically invoke a method with a POJO parameter using ArgumentConvertingMethodInvoker when a Map is actually provided as argument?
I'm trying to dynamically invoke a method using Spring's ArgumentConvertingMethodInvoker, where the method expects a POJO (e.g., UserDTO), but the arguments I'm passing in are Map<String, Object>...
0
votes
0
answers
51
views
Spring Boot 1.3.8.Release - @Configuration class and @Bean function - @Bean not working
We use Spring Boot 1.3.8 (old project - old version I know) and we have this @Configuration class within the application:
import org.springframework.context.annotation.Bean;
import org.springframework....
0
votes
2
answers
157
views
What happens first at startup of a Spring boot application - loading of the application.properties file or creations of beans annotated with @Bean?
I've this class:
@Slf4j
@Configuration
public class TxnIdGeneratorProperties {
@Bean
public TimeBasedTxnIdGenerator seqGenerator() {
if (log.isInfoEnabled())
log.info(&...
0
votes
1
answer
103
views
Cannot apply library properties in Spring Boot application
I created an Java Spring library to audit and log execution times during the execution of my application. I deployed it on SonaType and load it as a dependency in a demo project.
The properties of my ...
0
votes
2
answers
160
views
Spring boot bean to be initialized before another from the same type
I want to 'override' a bean from type MicrometerObservationCapability https://github.com/spring-cloud/spring-cloud-openfeign/blob/main/spring-cloud-openfeign-core/src/main/java/org/springframework/...
0
votes
1
answer
42
views
Multiple beans in context - how to dynamically select based on config?
I have this application that works fine for a single job:
interface Job {
void foo();
}
class JobA implements Job {
void foo() {...}
}
class JobB implements Job {
void foo() {...}...
0
votes
1
answer
292
views
@ConditionalOnProperty how to use twice on the same bean?
Is there any way to use @ConditionalOnProperty twice for the same bean?
I have two properties, that are mapped to "A" or "B" individually.
Spring configuration:
@Bean
@...
1
vote
0
answers
604
views
Multiple bean definition error after updating to Spring Boot 3.4
I can't post real code but this is a modified version of what I'm seeing, with fake class names. On startup of my Spring application, I see this log:
***************************
APPLICATION FAILED TO ...
0
votes
1
answer
246
views
Spring boot - Apache cxf logs BeanCurrentlyInCreationException at Runtime
I am setting up a soap service using Spring boot 3.4.3 and Apache cxf 4.1.1.
I use the simpelest setup from Spring initializer only selecting web dependency and apache cxf like below:
<dependencies&...
0
votes
1
answer
70
views
Validating dynamic Spring beans generated by BeanDefinitionRegistryPostProcessor
I have a class that implements the Spring BeanDefinitionRegistryPostProcessor:
package com.example.demo;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory....
1
vote
0
answers
42
views
Why the CamelRegistry does not resgister the latest MicrosoftExchangeOnlineOAuth2MailAuthenticator bean with the updated values?
I am working on a Springboot + Camel app wherein I am dynamically building the IMAP connection over Java DSL as shown below. My problem is that although I am able to read all the IMAP parameters ...
2
votes
0
answers
2k
views
@Bean method 'someBean' must not be declared as autowired; remove the method-level @Autowired annotation
Our Java / Spring boot application is using a library. The library has a class defined as below:
@Configuration
public class Test {
public Test() {
}
@Autowired
@Bean
SomeBean ...
1
vote
1
answer
85
views
Spring group validation does not work on autowired beans
Situation
I am trying to create a autoconfiguration in which some properties must pass validation only in specific cases. I have a service MyService which requires credentials properties.username and ...
0
votes
1
answer
141
views
Springboot doesn't create mapstruct bean
I have some mappers with the following code:
import org.mapstruct.Mapper;
import org.mapstruct.MappingConstants;
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public interface ...
0
votes
1
answer
113
views
Circular references error in spring security when starting application
I am trying to learn Spring Security. I have understood a bit, but I am encountering a cycle error that I cannot seem to resolve. I will also share the code for the classes with you.
Springboot ...
0
votes
2
answers
244
views
Spring Boot: How spring boot handle if we use both @Component and @Bean annotation for same class
In my spring boot application. I created a class name Book and annotated that class with @Component annotation. Then I created a AppConfig class with @Configration annotation and in that class created ...
0
votes
1
answer
50
views
Using MockBean to mock SessionFactory
I have a DAO impl class that I'm trying to write a unit test for using testng. My class has a SessionFactory autowired into it which is why I'm using the MockBean annotation in my test class. In my ...
0
votes
0
answers
76
views
How to use the configuration of database to conditionally load beans In SpringBoot?
My SpringBoot version is 2.3.4, database is Mysql 5.7.35
It's we all known that SpringBoot can use @ConditionalOnProperty to conditionally load beans.
Can we move the parameters from the configuration ...
0
votes
2
answers
88
views
Spring Boot - Bean configuration
I am trying to connect to a database which will hold log in information for my application.
I keep getting this error:
APPLICATION FAILED TO START
Description:
Field userDetailsService in com.neet....
1
vote
1
answer
78
views
Consider defining a bean of type service in your configuration
I have been learning Spring Boot for a week now yesterday I faced an error
`
Field db in com.example.test.tutorial.TutorialApplication required a bean of type 'com.example.test.tutorial.DB' that could ...
1
vote
1
answer
465
views
Spring not creating beans after Spring boot upgrade to 3.x from 2.7
I recently upgraded to Spring boot 3.0.12 from 2.7. But after doing the migration my integration tests are not running properly as they are missing spring beans. I started debug logging and it is not ...
1
vote
1
answer
327
views
Ensuring order in Spring Boot custom starter auto-configuration
I'm writing a custom Spring Boot starter and need to check for certain requirements in the client application's context. I do this at @Conditional evaluation time using custom Condition classes. One ...
0
votes
1
answer
1k
views
Spring boot @ConditionalOnBean does not detect AutoConfiguration bean
I want to ensure that the MyKafkaProducer bean is only activated when KafkaAutoConfiguration is loaded, so I have created the code as follows:
@Service
@ConditionalOnBean(KafkaAutoConfiguration.class)
...
0
votes
0
answers
317
views
Annotation-specified bean name 'solRepository' for bean class conflicts with JpaRepositoryBean while migrating to spring boot 3.2.x
I'm facing a classic issue in spring that states the following:
org.springframework.context.annotation.ConflictingBeanDefinitionException:
Annotation-specified bean name 'solRepository' for bean ...
1
vote
0
answers
122
views
multi-module bean not found
I am developing a service by combining Kotlin, Spring Boot, multi-module, and hexagonal architecture.
While implementing the login logic, I encountered the following error:
***************************
...
0
votes
0
answers
132
views
Why is the Spring Boot new version like this? The old version doesn't.Annotation-specified bean name 'application' for bean class [xxx.Application]
Why is the Spring Boot new version like this? The old version doesn't.Annotation-specified bean name 'application' for bean class [xxx.Application]
This is a multi-module demo.
Annotation-specified ...
1
vote
1
answer
1k
views
Create a Multipartresolver bean in Spring-6
in spring5 we can create a bean like below.
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name=&...
0
votes
1
answer
305
views
Create test bean for a JpaRepository
I have a Spring Boot application halfway through migrating from old style Hibernate DAOs using a SessionFactory to Spring's JpaRepositories.
The problem I am facing is that in unit tests, I have some ...
-1
votes
1
answer
1k
views
Caused by:NoUniqueBeanDefinitionException: No qualifying bean of type available: expected single matching bean but found 2
problem statement: conflict between two beans with same name
example scenario
Inteface
public interface FakeInterface{
}
implementations which will act as beans
@Slf4j
@Service
public class ...
0
votes
0
answers
61
views
How to create beans of the same class for multiple template parameters in Spring
I want to send events and messages of different object types using Kafka topics. So I have producer configuration class in which I create the beans of the class KafkaTemplate and ProducerFactory:
@...
0
votes
1
answer
52
views
Autowired annotation not working for Service Class
I'm creating a desktop app using spring and javafx. The issue that I'm facing is with a repository that I have. I'm using the Service component to create an excel file, but I have some issues with the ...
0
votes
1
answer
550
views
Invalid connection string format, a valid format is: "host:port:sid"
I have the error:
"Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Exception IO: Invalid connection string ...
0
votes
1
answer
288
views
Jackson CsvMapper Bean not registering JavaTimeModule
I recently attempted to use the Jackson CsvMapper and I found a peculiar "feature" that I think is a bug in the jackson lib. If I create a Spring bean for the mapper it appears to ignore the ...
2
votes
1
answer
569
views
Custom "Condition" (org.springframework.context.annotation.Condition) that requires a dependency
I've seen several "how to write a custom Condition" (org.springframework.context.annotation.Condition)
https://docs.spring.io/spring-framework/docs/4.2.x/spring-framework-reference/html/...
0
votes
1
answer
982
views
Spring Boot Warn, when launching service - "Bean'org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration'"
After migrating Spring Boot version from 2.7.14 to 3.2.2 I get a warning when I start the service.
WARN [info-service,,]" 50964 --- [main] trationDelegate$BeanPostProcessorChecker : Bean 'org....
1
vote
2
answers
1k
views
Use docker api with Spring Boot
Basically, I have a task, I want to create a Docker container when running a Spring Boot application using Docker Java API and then use that container in various controllers. When I create Bean with ...
0
votes
0
answers
136
views
Autowired Beans (Nested) in a Request Controller are Null
I have migrated our project from Spring (5.2.x) to Spring 6 with Hibernate 5.6. I am using JDK17 and our application server is Tomee 9.1.1.
Now when I access one of the RestAPI, the beans(autowired) ...
0
votes
1
answer
67
views
UnsatisfiedDependencyException: Error creating bean with name
I am trying to develop a spring boot application with my sql as the database. i have used jdbc . when trying to add multiple sql statements in the create_table.sql file it gives me an error which ...
0
votes
0
answers
82
views
RefreshScope Not working when overriding PropertySourcesPlaceholderConfigurer
As per my requirement, i want to update configuration properties before they are used in creating beans. for that, i am extending PropertySourcesPlaceholderConfigurer and overriding loadProperties ...
0
votes
1
answer
450
views
Loading the right bean in the test profile in Spring boot
My application.yaml has the following entries:
spring:
profiles:
active: test
include: h2, test
key:
enabled: on
I have the following three bean definitions and would like to load the ...
3
votes
1
answer
1k
views
What does Spring Boot test default configurations warn "Parameter 'systemProperties' is deprecated"?
In a Spring Boot test, when I annotated with @SpringBootTest,
I get warning:
Parameter 'systemProperties' is deprecated: Use systemPropertyVariables instead.
Why is that and how can I fix it?
This ...
-1
votes
3
answers
146
views
Constructor base dependency injection not working?
It's my first time encountering this error that says
`Description:
Parameter 0 of constructor in com.team.zah.blog.service.Impl.PostServiceImpl required a bean of type 'com.team.zah.blog.repository....
0
votes
0
answers
52
views
circular dependency in spring bean
I created two versions of this code (started learning Java Spring this week):
//version 1 (Complete)
public class Mello {
public void fun2()
{
System.out.println("inside mello&...
0
votes
1
answer
927
views
Failed to instantiate [java.util.concurrent.Executor]: Illegal arguments to factory method 'getAsyncExecutor'; args: ; nested excep
When I upgraded in SpringBoot, I have a problem:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [java....
-7
votes
1
answer
94
views
Can I create an exception as a spring bean? [closed]
Can I create an spring bean which is a Java exception?
And then throw it multiple times ( lets say using different strings via setter)
0
votes
1
answer
61
views
Issue in creating instance of peeking reader in spring batch job
I have Master step
@Bean
public Step employeeMasterProfilePhoneStep() throws UnexpectedInputException, ParseException {
return stepBuilderFactory.get(Constant.MASTER_PHONE_STEP)
....
0
votes
0
answers
37
views
No qualifying bean of type 'com.assessment.bankSimulation.entity.BankAccount' available
So I'm Trying to make a demo banking app using multithreading. I have 2 classes BankAccount and Customer. I have annotated them both with @Component
Here is the exception im facing.
Exception in ...