Questions tagged [spring-bean]
A simple JavaBean managed by the Spring IoC container.
770
questions
0
votes
1
answer
16
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
26
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 ...
0
votes
2
answers
33
views
How to decorate interface driven controllers in spring mvc?
I have a interface driven controller like this:
@ResponseBody
@PreAuthorize("hasAnyRole('ADMIN', 'USER')")
@RequestMapping("/foo")
interface Foo {
@GetMapping("/{id}")...
0
votes
1
answer
27
views
JpaRepository keeps throwing exceptions
I recently stared learning spring data jpa.
I was directly following a bunch of tutorials but whan it comes to create repository I receive bean exceptions.
I tried using annotations and bean creating ...
0
votes
0
answers
24
views
Spring Boot created @Bean with interface the @PostConstruct not called with native image
Spring Boot 3.1.3
graalvm-jdk-17.0.8+9.1
When creating bean manually from configuration and return interface the bean @PostConstruct is NOT called.
The workaround I found is to return implementing ...
1
vote
0
answers
23
views
Consider defining a bean of type 'com.security.learnspringsecurity.Repositories.UserRepo' in your configuration
please refer the hierarchy
package com.security.learnspringsecurity.Repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import ...
0
votes
2
answers
62
views
Getting BeanCreationNotAllowedException on spring graceful shutdown
My spring boot application uses spring boot graceful shutdown setting. In the app I'm having queue listeners in the separate threads. Everything gets shut down correctly except that every now and then ...
0
votes
0
answers
81
views
Why are PROMETHEUS metrics not visible on prometheus endpoint?
I am trying to add a few custom gauges to PrometheusMeterRegistry. I can see the metrics (default) on prometheus endpoint when I add the dependency, but I dont see them anymore when i create a bean ...
-1
votes
1
answer
100
views
Using JavaPoet to create Sping Beans
I'm working on spring as part of my classwork and using Javapoet for code generation.
Is there a way I can create Spring Beans via JavaPoet?
I have a use case where I wish to create Java classes based ...
0
votes
2
answers
20
views
Spring Batch - How to dynamically invoke a Step Configuration to reinitialise partitioner instance
I have a spring batch job consisting of ItemReader, ItemProcessor and NoOpItemWriter.
I have a rest controller that starts the job using some job parameters.
The item reader reads from a list ( that ...
-2
votes
1
answer
91
views
What are the differences between object and spring beans? [closed]
You may explain the differences between spring bean and object.
I also still don't understand beans in spring What exactly is the role of spring beans in spring?
Apparently, the definition that beans ...
0
votes
0
answers
20
views
Spring Unsatisfied Dependency Exception, Error creating bean with name "Controller" when using Quartz Job Scheduler
Quartz Config XML that i have:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www....
1
vote
1
answer
56
views
Generic Service implementation required a single bean, but 2 were found
I was trying to implement a generic ReadService with the methods that I want to implement for many entities (findById, findByIdToDto, findAll, findAllToDto), so in that way I will avoid writing the ...
0
votes
2
answers
247
views
Disable automatic autowiring of third party Bean
I am implementing a third party library that uses Spring, which is declaring a Filter in the following way:
@Bean
@Autowired
public Filter filter() {
return new Filter();
}
I load the ...
0
votes
1
answer
35
views
How to use RequestMapping with Functional Bean Definitions in Kotlin and Spring Boot 3?
I am working on upgrading a service from using Spring Boot 2.7 to Spring Boot 3. The project is using Kotlin and all beans are defined via functional bean definitions. Previously all routes worked as ...
0
votes
0
answers
51
views
@Scope("prototype") is not working in spring boot upgrade from version 2.1.7 RELEASE to 2.7.11 RELEASE
I have a bean annotated with @Scope("prototype"). It worked well with Spring boot 2.1.7 RELEASE. Spring created this bean only when requested from application context, but after upgrading ...
0
votes
0
answers
22
views
How exactly does the proxyMode parameter work in the @Scope annotation?
I have a simple class HomeController (singleton) and a HomeService (prototype, proxyMode = ScopedProxyMode.TARGET_CLASS).
@Controller
public class HomeController {
private final HomeService ...
0
votes
0
answers
54
views
Why is BeanFactoryPostProcessor invoked before creating BeanDefinition's for BeanFactory?
I am studying the internal structure of Spring and trying to understand the stages of the life cycle of beans, how and when they are created and so on.
Spring provides us with 2 interfaces for ...
0
votes
0
answers
238
views
After springboot 3.0 upgrade facing error: Scope 'request' is not active for the current thread when a rest endpoint is called
I have a Java Rest application written using springboot 2.x. I have upgraded it to java 17 and springboot 3.
The application starts fine after upgrade.
Application start up success message
But when I ...
0
votes
1
answer
199
views
Define a @Bean in @Configuration or @Component
I am currently working on implementing a consumer of a Azure Service Bus queue in a Spring Boot application as explained in Azure's official guide. The code that consumes the messages from the queue ...
0
votes
1
answer
56
views
when using @Value spring annotation, is it possible to leverage some sort of string interpolation?
Can I do something like this?
private final static String myVar = "health.xyz.throughput";
@Value("${{myVar}:10}") // doesn't work of course
private Integer healthThroughput;
...
0
votes
0
answers
25
views
Function for creating scoped beans causing UnsatisfiedDependencyException due to absence of singleton bean?
I currently have the following code
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public A createScopedBeans(String s) {
return new A(s);
}
This function above is being called multiple ...
1
vote
2
answers
431
views
In Spring/Spring Boot how to make Bean initialised before Tomcat?
In Spring/Spring Boot how to make Bean initialised before Tomcat?
That is before these lines in log:
o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
o.apache....
0
votes
2
answers
82
views
Error creating bean with name 'appUserService' defined in class path resource: Unsatisfied dependency expressed through constructor parameter 0
When I compile my spring project, I got the following error.
Error creating bean with name 'appUserService' defined in file [K:\ChessGE JAVA\ChessGe\target\classes\com\example\chessge\appuser\...
0
votes
1
answer
280
views
Spring @Bean configuration is not working, loses it's config when autoscanned in development environment
I have a configuration class to create a WebClient with some specifis SSL setup. There is another WebClient bean in the service, so I used a Qualifier annotation. Before moved this to a Configuration ...
0
votes
1
answer
821
views
How to fix 'Error Creating Bean' (BeanCreationException) in Maven Spring Boot Application?
I am creating a User Registration System using Maven & Java Spring Boot. While I am able to get the project to successfully build, the application cannot start with the following error trace:
. ...
0
votes
0
answers
75
views
Spring bean gutter Icon not being displayed in Intellij idea
Idea warn: "Autowired members must be defined in valid Spring bean (@Component|@Service|...)"
Multi-module project, it is determined that the dependency has been introduced, and the project ...
1
vote
1
answer
330
views
Defining custom bean name generator based on package which the class belong to
We are planning to create some java libraries and use these common jars in spring boot application by adding them as maven dependencies.
These jars are expected to make use of spring features like ...
0
votes
0
answers
53
views
Missed connection in Spring Beans Dependancies diagram with intellijIDEA
I'm working on a simple Spring Application with 3 classes :
ProductService
ProductRepo
ProductConfig
I try to show the diagram of Beans Dependencies
for a particular Bean **ProductService **
here ...
1
vote
1
answer
253
views
How to mock Bean that makes rest api request in spock test?
So I have the application which makes a rest api request and I added bean annotation as follows
@Configuratin
public class RequestService {
@Autowired
RestTemplate restTemplate;
@Autowired
...
1
vote
1
answer
273
views
how to create bean if another bean exists or not but don't throw exception
i have auto-config like shown below
public class ConfigClass {
//create a builder
@Bean
public Builder builder() {
return new Builder();
}
//create a bean if SampleBean ...
0
votes
0
answers
22
views
how do i make an existing class to singleton?
i'm new to spring.
i have my class as below in main/module1
public class MainClass extends Thread {
protected final SomeClass someclass;
//constructor
public MainClass(SomeClass s) {
super(s.id);
...
0
votes
0
answers
65
views
Lombok Builder in Spring XML Configuration
i need to refractor an costructor with more than 12+ parameters and without setters, so i thought that builder will be a nice solution.
I will use Builder from lombok annotation so i need to somehow ...
1
vote
1
answer
92
views
How to execute a runnable instead of bean creation in Spring configuration?
There is a usual configuration creating beans and performing an action using some of them.
The intention of initialAction is just execute print("Hello...") if certain conditions are in place ...
2
votes
0
answers
264
views
Bean is no longer being autowired after Spring 5.3 Upgrade
I upgraded my package from Spring 4.3 to Spring 5.3 which has caused a issue I am completely to solve, for some reason a Bean that is created and works under 4.3 is being created, but not wired in. ...
0
votes
1
answer
412
views
Using a spring-beans .xml file (in 'resources' folder) from a shared module with gradle multi module (subproject)
(To assist with this question, I have github links at the bottom of this question)
I have (and am "starting with" the below gradle multiple module/project)
settings.gradle
rootProject.name ...
0
votes
0
answers
50
views
Programmatically register EmbeddedDatabaseAutoConfiguration bean inside BeanDefinitionRegistryPostProcessor to use embedded Postgres
I am registering a bean for EmbeddedDatabaseAutoConfiguration but it is never acted upon.
Is something missing for it to be processed in the same manner as if the annotation was present? I'd like to ...
0
votes
0
answers
46
views
I am getting two different instances of same bean when scope is different in property bean (request scope) in spring xml file
I have a bean let say MyRequestBean whose scope is defined as "request" in spring xml file.
This bean is added as a property in another spring bean let say MyConversationBean whose scope is ...
0
votes
0
answers
40
views
Refresh / Reinitialize a Spring Bean
I need to refresh / reinitialize a Spring Bean. My code snippet is as per below:
@Bean
@Qualifier("service")
Service myService() {
return new Service(file1, file2);
}
@Scheduled(cron = &...
0
votes
0
answers
70
views
How to check if property is static in String BeanWrapper PropertyDescriptor?
I want to print all instance properties of an object.
Unfortunately the class MyObject contains static method "setThird", which matches naming pattern for properties. And even though the ...
0
votes
1
answer
83
views
spring bean override with custom implementation
I want to override a spring implantation and use my own bean. For example CompositeEnvironmentRepository which is a spring bean, i want to write my own. One way is to delete this bean from the spring ...
0
votes
0
answers
41
views
Spring component returning list from previous run
I have a spring component which looks like this. It has other beans auto-wired to it. And these components are returned as a list by the method getConfigurators(String Id)
@Component
public class ...
0
votes
0
answers
478
views
MapStruct Mapper Bean not found
I am trying to create a mapper for my Capteur class :
Capteur:
package fr.projettresscientifique.reel.referentielreel.model.java;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public ...
0
votes
1
answer
188
views
How to dynamically provide different .properties files for beans of same type?
Let's provide context, before I try to explain the need I'd want to meet.
Class - AnimalShelterConfiguration
@Configuration
public class AnimalShelterConfiguration {
@Bean
public List<...
0
votes
1
answer
190
views
How to create a non reusable bean on springboot
By default, on springboot, when we declare a method with @Bean, the object instance will be shared across all objects that request for @Autowired that class...
What if I want spring to deliver ...
0
votes
0
answers
29
views
Resolve property placeholders before returning a Properties bean
Using Spring XML configuration(only), how do I return a Properties object with resolved placeholders?
Given this setup, the output is
PW: ${db.password}
application.properties:
spring.datasource....
0
votes
0
answers
50
views
How can i pass a package reference as argument to a dependency
I've created a spring boot util project with maven to provide useful functions for cross-cutting concerns like exception handling of other maven projects, that can be imported as a dependency from the ...
0
votes
0
answers
104
views
Apache Poi Workbook - problem creating Workbook as a spring IOC managed bean
I have the certain problem:I want to register Apache Poi Workbook as a bean but when I try to do that an exception is thrown stating that my file is zero bytes long
Here is the exact exception: ...
0
votes
1
answer
83
views
Importing @AutoConfiguration class while using @ConditionalOnMissingBean in it
I have ConfigA in one module and ConfigB in other module and they look like following snippet.
@Configuration
@Import({ConfigB.class})
public class ConfigA {
@Bean
Foo foo1(){}
}
@...
0
votes
1
answer
75
views
Bcrypt bean could not be found when defined in Main class and other service bean with same problem when injected in Main Class
I create this simple project to test a bug in another project. I have a main class (AppApplication) and a service class (CommandUser). The goal is to use the bean declared in class main on CommandUser ...