spring-bean

Why is spring boot not finding my beans?

梦想与她 提交于 2019-12-11 10:47:22
问题 i have following error: Parameter 0 of constructor in com.yyy.zzz.xxx.service.ControlService required a bean of type 'com.yyy.zzz.xxx.service.composeXML.ComposeCounterService' that could not be found. Usually this is because i forget to annotate either the Service or the interface, but i've been looking classes the whole morning and cant find any missing annotations.. interface at this point is just: @Component public interface ComposeCounterService { CLASSX init(List<YYY> owners) throws

autowire distinct beans in abstract class

喜夏-厌秋 提交于 2019-12-11 10:32:30
问题 I have the following problem: Suppose I have an abstract class lets say: public abstract class AbstractHbmDao implements SomeInterface { @Autowired protected SessionFactory sessionFactory; //getters & setters //interface stuff } Then several implementations of SomeInterface -> A_Interface , B_Interface , etc. This is ok if I use the same SessionFactory for every implementation. The problem is I want to use distinct SessionFactory for distinct group of of implementations and I do not want to

How to reload configuration bean with properties from database

烂漫一生 提交于 2019-12-11 08:36:56
问题 I need to create a spring javamail bean initialized with values from database for each mail sent. Based on this article, How to Load Application Properties from Database I've configured my PropertyPlaceholderConfigurer to load values from both properties file and database. I have the following bean( mailSender ) in my java configuration class for sending mail from my application which loads host, port, username and password from the database, @Configuration public class MailSenderConfig {

Are there any considerations when using Spring bean IDs that contain spaces?

依然范特西╮ 提交于 2019-12-11 08:07:17
问题 Most examples of Spring bean IDs use Java-style variable names, such as someBean . However, that style isn't enforced; in fact, spaces and some other special characters are permitted (as of Spring 3.1 and later). An argument can be made for using more verbose bean IDs, such as: <bean id="Some Bean" /> So far I've encountered only one issue with using bean IDs like that (see How can I declare a Spring `depends-on` attribute with a bean ID that contains spaces?). Are there any other important

Spring 3 - Annotation based Bean Validation

眉间皱痕 提交于 2019-12-11 05:02:47
问题 I am building a REST API. Its made up of a Resource ( @Controller ) which returns a response 204 even when one of the mandatory field is not present. I am using Spring 3.1, validation-api (1.1.0.Final) & Hibernate-validator(4.3.0). Not sure if Hibernate-validator plays any role here. <dependency> <groupId>javax.validation</groupId> <artifactId>validation-api</artifactId> <version>1.1.0.Final</version> </dependency> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-validator<

How to make a UserDetailsManager available as a bean

℡╲_俬逩灬. 提交于 2019-12-11 02:43:30
问题 I'm experimenting with spring-security for authentication and want to be able to add users at runtime. I figured using UserDetailsManager would be minimally intrusive. How do I make it available as a bean, so that I can access it in controllers and other objects? The Code I was starting with is as follows: @Autowired public void configureGlobal(AuthenticationManagerBuilder auth, DataSource dataSource, PasswordEncoder enc) throws Exception { auth.jdbcAuthentication().dataSource(dataSource)

Why would Spring 3 @Component names clash when they have different packages?

爱⌒轻易说出口 提交于 2019-12-11 01:34:01
问题 I've got two classes: package package1; @Component public class MyClass1 { ... package package2; @Component public class MyClass1 { ... When I run failsafe (in maven) - I get the following error in spring (that I don't get in surefire): test1(package3.MyIntegrationTest) Time elapsed: 6.737 sec <<< ERROR! java.lang.IllegalStateException: Failed to load ApplicationContext Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name

Does Spring's @RequestScope automatically handle proxying when injected in singleton beans?

五迷三道 提交于 2019-12-07 15:37:52
问题 I'm using a Java8/Spring Boot 2 application. I want to inject a request-scoped bean into a singleton bean. The official documentation highlights that either a proxy or ObjectFactory/Provider should be used to ensure always getting the correctly scoped bean at runtime in the singleton bean. However, the @RequestScope annotation seems to "automatically" set some kind of proxy, as explained in the answer to this question. I'm now wondering if the following three implementations are in fact

What's the difference between @Lazy annotation and lazy-init attribute of <bean/> tag?

柔情痞子 提交于 2019-12-07 13:32:51
问题 As per my understanding, @Lazy annotation and lazy-init attribute of tag should have the same functionality. But when I developed the following code, it's showing distinct behaviours. In the following code, I was expecting :- (Circular Dependency Error) org.springframework.beans.factory.BeanCurrentlyInCreationException I have attached code using @Lazy annotation, as per my expectations it should not allow Circular Dependency. @Component public class A { private B b; @Autowired public A(@Lazy

Not loading a Spring bean when a certain profile is set

空扰寡人 提交于 2019-12-06 20:13:04
问题 Background: So, I've got several beans that interface external systems. For development, it's convenient to mock the external systems and replace the interfacing beans with some implementations that produce more or less static responses. So what I've been doing is to create an interface, the real implementation and a stub implementation like this: public interface ExternalService { // ... } @Service public class ExternalServiceImpl implements ExternalService { // ... } @Service @Primary