spring-bean

SpringBoot - BeanDefinitionOverrideException: Invalid bean definition

我的未来我决定 提交于 2019-12-18 12:09:22
问题 I am trying to setup DynamoDB locally with Spring Boot. Initially I got the setup working and was able to write/save to DynamoDB via a repository. From that point I added more classes to build my application. Now when I try to start my application, I get the following exception: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'agentRepository' defined in null: Cannot register bean definition [Root bean: class [org.socialsignin

Dynamically add new queues, bindings and exchanges as beans

会有一股神秘感。 提交于 2019-12-17 19:35:22
问题 I'm currently working on a rabbit-amqp implementation project and use spring-rabbit to programmatically setup all my queues, bindings and exchanges. (spring-rabbit-1.3.4 and spring-framework versions 3.2.0) The declaration in a javaconfiguration class or xml-based configuration are both quite static in my opinion declared. I know how to set a more dynamic value (ex. a name) for a queue, exchange or binding like this: @Configuration public class serverConfiguration { private String queueName;

Spring bean with runtime constructor arguments

拈花ヽ惹草 提交于 2019-12-17 18:03:57
问题 I want to create a Spring bean in Spring Java configuration with some constructor arguments passed at runtime. I have created the following Java config, in which there is a bean fixedLengthReport that expects some arguments in constructor. @Configuration public class AppConfig { @Autowrire Dao dao; @Bean @Scope(value = "prototype") **//SourceSystem can change at runtime** public FixedLengthReport fixedLengthReport(String sourceSystem) { return new TdctFixedLengthReport(sourceSystem, dao); } }

Spring FactoryBean

北城余情 提交于 2019-12-14 03:43:04
问题 I'm trying to grasp Spring's FactoryBean and I've had and issue. Could you please see my sources below and answer. It's my app context: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www

BeanDefinitionRegistryPostProcessor - How to register a @Configuration class as BeanDefinition and get its @Beans registered as well

夙愿已清 提交于 2019-12-13 11:50:29
问题 Let's suppose I have this @Configuration class: @Configuration public class SomeConfig{ @Bean public MyBean myBean(){ return new MyBean(); } @Bean public Another anotherBean(){ return new AnotherBean(); } } I have a class that implements BeanDefinitionRegistryPostProcessor to add certain BeanDefinition s. On it I also would like to import SomeConfig so that its beans are added to the context: @Override public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws

How to change a class's metaClass per test

余生长醉 提交于 2019-12-13 03:05:13
问题 I'm using the ExpandoMetaClass to make a service always return success in an integration test but I would like to have one test that actually fails. Example use of ExpandoMetaClass: static { ExpandoMetaClass someService = new ExpandoMetaClass(Object, false) someService.accessAnotherSystem = { return 'success' } someService.initialize() SomeService.metaClass = someService } Note: currently the service isn't defined for the controller but since it's a spring bean referencing the class named

How to get externally defined bean in java config

若如初见. 提交于 2019-12-12 11:01:38
问题 I have a java config class that imports xml files with the @ImportResources annotation. In the java config I'd like to reference to beans that are defined in the xml config, e.g. like: @Configuration @ImportResource({ "classpath:WEB-INF/somebeans.xml" } ) public class MyConfig { @Bean public Bar bar() { Bar bar = new Bar(); bar.setFoo(foo); // foo is defined in somebeans.xml return bar; } } I'd like to set the bean foo that has been defined in somebeans.xml to the bar bean that will be

java.lang.NoSuchMethodError: org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver: method <init>()V not found

无人久伴 提交于 2019-12-12 00:38:08
问题 I am developing Spring + MVC + RestEasy example. I was successfully able to developed the code, but I see the below error. It looks like to dependency mismatched issue. I already frusted to solve this issue, but unable to fixed it yet. I uploaded source code here: https://github.com/test512/RestEasy-Spring-MVC-Hibernate org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter':

Classdefnotfound exception while using bean.xml in spring

陌路散爱 提交于 2019-12-11 12:26:40
问题 org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@fb509a: startup date [Fri Jul 17 21:34:24 IST 2015]; root of context hierarchy Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/core/OrderComparator$OrderSourceProvider at org.springframework.context.support.AbstractRefreshableApplicationContext.createBeanFactory(AbstractRefreshableApplicationContext

Spring passsing autowired object to class constructor

亡梦爱人 提交于 2019-12-11 11:47:32
问题 I got problem with my SpringMVC application I have class annotated with @Component with 2 fields annotated with @Autowired @Component public class Crud { private final Logger logger = LoggerFactory.getLogger(Crud.class); private final Map<String, Database> dataSources = new HashMap<>(); @Autowired private DataSource clientDataSource; @Autowired private DataSource adminDataSource; public Crud(){ dataSources.put("client", new Database(clientDataSource)); dataSources.put("admin", new Database