草庐IT

conditionally-defining-spring-bea

全部标签

java - 为某些包 Spring MVC 设置不同的 ObjectMapper

有没有办法使用spring为我的项目中的某些包设置HttpMessageConverter?@Configuration@EnableWebMvc@ComponentScan(basePackageClasses=MyConfig.class)publicclassMyConfigextendsWebMvcConfigurerAdapter{@OverridepublicvoidconfigureMessageConverters(List>converters){for(HttpMessageConverterconverter:converters){if(converterins

java - 在 liquibase CustomTaskChange 类中使用其他 spring bean

我需要做一些数据迁移,这太复杂了,无法在liquibase变更集中完成。我们使用Spring这就是为什么我编写了一个实现liquibase.change.custom.CustomTaskChange类的类。然后我从变更集中引用它。到目前为止一切都很好。我的问题是:是否可以从此类中访问其他springbean?当我尝试在此类中使用Autowiring的bean时,它为null,这让我认为此时Autowiring还没有完成?我还在其他一些线程中读到,Liquibasebean必须在所有其他bean之前初始化,对吗?这是我写的类的片段:@ComponentpublicclassUpdate

java - Spring Oauth 端点的模拟服务器

我正在尝试进行集成测试,以了解当我的注册端点失败时的行为。我的注册端点是一个由外部源提供的API(由SpringOAuth保护)。客户端网站使用客户端SpringOauth与API进行通信。我想做的是模拟API,但是,我遇到了请求不针对模拟端点的问题;org.springframework.web.client.ResourceAccessException:“http://localhost:8081/oauth/token”的POST请求上的I/O错误:连接被拒绝:连接;嵌套异常是java.net.ConnectException:Connectionrefused:connect

java - spring-hateoas 0.8.0.RELEASE 与 Spring 4 的兼容性

我正在使用0.8.0.RELEASE版本的spring-hateos,它在3.2.3.RELEASE版本中具有spring库(spring-core和spring-webmvc)作为编译时依赖项。但是,在运行时,我想在版本4.2.2.RELEASE中使用spring-core和spring-webmvc。有谁知道这个版本的spring-hateos是否与最新版本的spring库兼容? 最佳答案 查看changelog,对Spring4.0.x的支持从版本0.17.0.RELEASE开始Changesinversion0.17.0.R

java - Spring @RequestParam 和 Controller 接口(interface)

我对@RequestParam(value="someValue")的行为感到困惑。在docs据说Whenusingcontrollerinterfaces(e.g.forAOPproxying),makesuretoconsistentlyputallyourmappingannotations-suchas@RequestMappingand@SessionAttributes-onthecontrollerinterfaceratherthanontheimplementationclass.如果我将@RequestParam放在我的Controller接口(interface)

java - Spring 状态机的替代品

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。关闭6年前。Improvethisquestion我在一些基本的SpringMVC应用程序中使用了Spring状态机。我必须承认,它的配置和使用非常简单。但它也有很多局限性,主要是因为它处于非常早期的开发阶段。我还遇到了一些工作流引擎,比如Activiti,它是anopen-sourceworkflowenginewritteninJava和stateless4j这是一个LightweightJavaStateMac

java - 如何使用 Spring Boot/slf4j 在日志文件的名称中包含日期?

和SettingalogfilenametoincludecurrentdateinLog4j是同一个问题,但是如何应用到slf4j自带的SpringBoot中呢?应用程序属性spring.application.name=keywordslogging.file=logs/${spring.application.name}.log 最佳答案 如所述hereSpringBoothasaLoggingSystemabstractionthatattemptstoconfigureloggingbasedonthecontentoft

java - 在 Spring Data REST 中获取和更新延迟加载的许多字段

我如何正确公开延迟加载许多字段,以便用户可以GET/PATCH/POST/DELETESpringDataREST中的多对多实体关系?例如,给定一个Student实体和Teacher实体,它们由多对多关系绑定(bind),具有以下POJO:@EntitypublicclassTeacher{//ownerofbidirectionalrelationship@Idprivateintid;privateStringname;@ManyToMany(fetch=FetchType.LAZY)@JoinTable(name="teacher_student",joinColumns=@Jo

spring - 在 java 中使用 elasticSearch 2.3.3 按索引名称和类型删除索引

我在java中有一个项目,我使用Elasticsearch2.3.3为数据编制索引。索引有两种类型。我的索引文档如下所示:{"took":10,"timed_out":false,"_shards":{"total":1,"successful":1,"failed":0},"hits":{"total":3,"max_score":1,"hits":[{"_index":"test_index","_type":"movies","_id":"uReb0g9KSLKS18sTATdr3A","_score":1,"_source":{"genre":"Thriller"}},{"_i

java - Spring - 支持 QueryDsl 的高级比较器

在officialdocumentation之后,添加@EnableSpringDataWebSupport我的Spring配置注释允许自动注入(inject)Predicate查询类:@RequestMapping(method=RequestMethod.GET,path="/find")publicResponseEntity>find(Pageablepageable,PagedResourcesAssemblerassembler,@QuerydslPredicate(root=Foo.class)Predicatepredicate){Pagefoos=fooReposit