草庐IT

configurer

全部标签

java - 在 Spring 中使用 @Configuration 创建一个 bean 集合

如何使用带有@Configuration注释的类创建一个将由Spring正确管理的bean集合。我想做这样的事情:@ConfigurationpublicConfig{@AutowiredprivateSomeConfigurationconfig;@BeanpublicListmyBeans(){Listbeans=newArrayList();for(Devicedevice:config.getDevices()){beans.add(newMyBean(device));}returnbeans;}}但是MyBean实例没有经过后处理。所以他们的@Autowired方法没有被调

spring - Spring中的@Configuration和@Component有什么区别?

@ComponentScan使用@Configuration和@Component创建bean。交换时,这两个注释都可以正常工作。那有什么区别呢? 最佳答案 @ConfigurationIndicatesthataclassdeclaresoneormore@BeanmethodsandmaybeprocessedbytheSpringcontainertogeneratebeandefinitionsandservicerequestsforthosebeansatruntime@ComponentIndicatesthatana

java - Spring Security Configuration @Order 不是唯一异常

我尝试在我的SpringSecurity配置中注册多个过滤器,但是我总是遇到同样的异常:04-Nov-201514:35:23.792WARNING[RMITCPConnection(3)-127.0.0.1]org.springframework.web.context.support.AnnotationConfigWebApplicationContext.refreshExceptionencounteredduringcontextinitialization-cancellingrefreshattemptorg.springframework.beans.factory.

java - 带有 PropertyPlaceholderConfigurer bean 的 Spring @Configuration 文件无法解析 @Value 注释

我有以下配置文件:@ConfigurationpublicclassPropertyPlaceholderConfigurerConfig{@Value("${property:defaultValue}")privateStringproperty;@BeanpublicstaticPropertyPlaceholderConfigurerppc()throwsIOException{PropertyPlaceholderConfigurerppc=newPropertyPlaceholderConfigurer();ppc.setLocations(newClassPathReso

java - Spring 数据: Java configuration for MongoDB without XML

我试过SpringGuideAccessingDatawithMongoDB.我想不通的是如何将我的代码配置为不使用默认服务器地址而不使用默认数据库。我已经看到了许多使用XML的方法,但我正在尝试使用完全无XML的配置。有没有人有一个示例,可以在没有XML的情况下设置服务器和数据库,并且可以轻松地集成到他们在SpringGuide中显示的示例中?注意:我确实找到了如何设置集合(搜索短语“我的文档将保存到哪个集合中”onthispage。谢谢!附言与JPA的SpringGuide相同的故事——你如何配置数据库属性——但那是另一篇文章:) 最佳答案

java - Spring 数据: Java configuration for MongoDB without XML

我试过SpringGuideAccessingDatawithMongoDB.我想不通的是如何将我的代码配置为不使用默认服务器地址而不使用默认数据库。我已经看到了许多使用XML的方法,但我正在尝试使用完全无XML的配置。有没有人有一个示例,可以在没有XML的情况下设置服务器和数据库,并且可以轻松地集成到他们在SpringGuide中显示的示例中?注意:我确实找到了如何设置集合(搜索短语“我的文档将保存到哪个集合中”onthispage。谢谢!附言与JPA的SpringGuide相同的故事——你如何配置数据库属性——但那是另一篇文章:) 最佳答案

java - 如果 Spring 可以成功拦截 @Configuration 类中的类内函数调用,为什么它在常规 bean 中不支持呢?

我最近注意到Spring在@Configuration类中成功拦截了类内函数调用,但在常规bean中没有。这样的电话@RepositorypublicclassCustomerDAO{@Transactional(value=TxType.REQUIRED)publicvoidsaveCustomer(){//someDBstuffhere...saveCustomer2();}@Transactional(value=TxType.REQUIRES_NEW)publicvoidsaveCustomer2(){//moreDBstuffhere}}无法启动新事务,因为虽然saveCus

java - Spring Boot 1.4 测试 : Configuration error: found multiple declarations of @BootstrapWith

按照此处的官方文档:http://docs.spring.io/spring-boot/docs/1.4.0.M2/reference/htmlsingle/#Testing我想像这样测试我的一种RESTAPI方法:@RunWith(SpringRunner.class)@WebMvcTest(LoginController.class)@SpringBootTest(classes=Application.class)publicclassAuthorizationServiceTest{@AutowiredprivateTestRestTemplaterestTemplate;@T

java - 在 .war 之外引用 configuration.properties

我想部署一个war,war应该从war外部获取一些属性(让我们说.war文件在哪里,同一个目录。)目前这是我找到的最佳解决方案:但是这个解决方案迫使我将其始终保留在主目录中。我希望它位于我部署.war的tomcatwebapps目录中。我只是在寻找涉及绝对路径的解决方案。如果相对路径绝对不可能,那么我会考虑使用绝对路径。提前致谢。 最佳答案 这是一种解决方案:如果有什么更好的,请告诉我,例如,如果我可以摆脱catalina家庭引用并以某种方式使其成为更通用的引用。 关于java-在.wa

spring - 配置数据源失败 : 'url' attribute is not specified and no embedded datasource could be configured

我正在使用MongoDB处理SpringBootBatch示例,并且我已经启动了mongod服务器。当我启动我的应用程序时,我收到以下错误。关于这个问题的任何指针?***************************APPLICATIONFAILEDTOSTART***************************Description:FailedtoconfigureaDataSource:'url'attributeisnotspecifiedandnoembeddeddatasourcecouldbeconfigured.Reason:Failedtodetermineas