【java之spring mvc之helloworld】教程文章相关的互联网学习教程文章

java – 将Spring Bean注入基于注释的Bean Validator【代码】

我在Spring MVC应用程序中为MultipartFile编写了一个自定义ConstraintValidator,它看起来像这样:@Documented @Retention(RetentionPolicy.RUNTIME) @Constraint(validatedBy = {MultipartFileNotEmptyValidator.class}) @Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.CONSTRUCTOR, ElementType.PARAMETER }) public @interface MultipartFileNotEmpty {String message() default "...

java – Spring测试:如何将配置默认配置为@AnnotationDriven?【代码】

目前我的课看起来像@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(loader = AnnotationConfigContextLoader.class, classes = {DemographicAttributesManager.class}) public class DemographicAttributesManagerTest {@Autowiredprivate DemographicAttributesManager demographicAttributesManager;@Testpublic void testGetGenders() throws Exception {final Map<Integer, String> genders = demographicAtt...

java – Spring Boot – @RestController的@ConditionalOnExpression【代码】

我想基于配置启用/禁用@RestController,为了实现它我正在尝试使用@ConditionalOnExpression注释. 使用静态硬编码值正常工作:@RestController @ConditionalOnExpression("true") public class MyRestController {@RequestMapping("/hi")public String hi() {return "hi";} }但是,在SpEL表达式中使用动态属性值总是导致不加载@RestController:@RestController @ConditionalOnExpression("${my.rest.controller.enabled:false}") pu...

java – Spring Batch 3.0.2与Spring Core 4.1.x的集成 – 使用@EnableBatchProcessing的合适方法是什么?【代码】

我正在尝试使用Spring Boot运行Spring Batch Admin应用程序,看起来我有同样的问题.首选解决方案是使用Java配置而不是XML. 将@EnableBatchProcessing与Spring Batch Admin一起使用会有什么合适的解决方案? 我看过this question,但我无法解决这个问题. 先感谢您. Spring Batch配置:@Configuration @EnableBatchProcessing @ImportResource({"classpath:org/springframework/batch/admin/web/resources/servlet-config.xml","classp...

java – spring 4.2应用程序事件用Spring MVC触发两次,为什么?【代码】

我正在使用Spring 4.2.0.BUILD-SNAPSHOT events,由于某些原因我还没想到,监听器在发布任何事件后都会触发两次,无论是从ApplicationEvent还是任意事件扩展,但是在运行测试用例时一切都按预期工作,现在想知道是什么正在继续使用Spring MVC上下文中的注释驱动事件 事件发布界面public interface ListingRegistrationService {public void registerListing(ListingResource listing);}@Component class ListingRegistrationServiceImpl...

java – 在Spring中为MethodArgumentNotValidException的@ExceptionHandler添加参数【代码】

我有一个Spring控制器,用hibernate验证器验证传入的请求. 当请求无效时,验证程序抛出MethodArgumentNotValidException.是否可以将附加类作为参数添加到异常的处理程序方法中? 这就是我所拥有的:@RequestMapping(value = "/...", method = RequestMethod.POST) @ResponseBody public Response handleCustomObject(@Valid @RequestBody CustomObject obj) {//.. }@ExceptionHandler(MethodArgumentNotValidException.class) @Respo...

java – Spring RestTemplate readtimeout属性不能正常工作 – 奇怪的问题【代码】

我想要消耗2个服务,并希望有不同的超时.所以,我已经覆盖了Spring的SimpleClientHttpRequestFactory并在我的HttpDaoImpl中使用它. 现在一切都在一个环境中工作,但完全相同的EAR在其他环境中不起作用,并且只有两个环境的区别在于我连接的服务URL是一个负载平衡URL而另一个是非LB.问题出现在负载均衡的服务URL中. 问题是每次httpReadTimeout生效或正在使用但不是XYZHttpReadTimeout,即使我有条件地设置超时. 这是一个非常奇怪的问题,因...

java – Spring Integration – 入站文件端点.如何正确处理文件.【代码】

我有一个Spring集成流程如下.<int-file:inbound-channel-adapter id="filesIn"directory="file:${incomingDir}" filename-pattern="*.txt" prevent-duplicates="true"><int:poller id="poller" fixed-delay="5000"/></int-file:inbound-channel-adapter><int:splitter input-channel="filesIn" ref="filesSplitterService"method="splitFilesToReportContent"output-channel="reportProcessIn"/><int:channel id="reportProcessIn"...

java – 在Spring Boot中使用templates / includes【代码】

即时’开发’使用Spring Boot创建的应用程序,我不太确定如何管理模板. 我有两种方法可以做到这一点: 使用自定义标记并将HTML / JSP文件的值作为String返回并使用它 像这样的东西<th:header></th:header> <!-- This would be the header (The implementation of this tag in Java) --><body>Things that are not common<th:footer></th:footer><!-- This would be the footer --> </body> 另一种方式可能是使用包括,但我不太确定如...

java – Spring Security getAuthentication()返回null【代码】

我正在尝试从Spring Boot AngularJS应用程序返回当前登录的用户,但SecurityContextHolder.getContext().getAuthentication()返回null. 安全配置:@Configuration @Order(SecurityProperties.ACCESS_OVERRIDE_ORDER) @EnableGlobalMethodSecurity(prePostEnabled = true) public class SecurityConfig extends WebSecurityConfigurerAdapter {@Autowiredpublic void configureGlobal(AuthenticationManagerBuilder auth) throws Exc...

java – Spring Security – BcryptPasswordEncoder【代码】

我在我们的应用程序中使用Spring安全性,并希望使用存储在数据库中的密码验证用户输入以获取更改密码选项. 密码在DB中按如下方式存储.user.setPassword(new BCryptPasswordEncoder().encode("<userPassword>"));这里用户输入的密码使用上述逻辑编码并存储在DB中.现在我只是想从用户那里获取更改密码的密码.从用户获取密码后,我使用上述逻辑进行编码,并尝试与DB进行比较.即使我使用相同的编码逻辑,编码值似乎也不同. 我在WebSecurity...

java – Spring Data JPA – 是否可以对计算属性进行排序?【代码】

假设您有以下实体:@Entity public class Game {@Id@GeneratedValueprivate Integer id;private String name;private Calendar startTime;private int durationInSeconds;public GameStatus getStatus() {if( startTime.after(Calendar.getInstance())){return GameStatus.SCHEDULED;} else {Calendar endTime = Calendar.getInstance();endTime.setTime(startTime.getTime());endTime.roll(Calendar.SECOND, durationInSeconds);i...

java – spring boot:仅用于Web应用程序开发?【代码】

我想让自己更熟悉Spring Data&春季启动.我查看了一些示例,找不到在tomcat等服务器上运行它的方法. 是否有可能开发一个简单的客户端应用程序,它只与数据库通信并使用spring数据或spring boot在操作系统上运行?解决方法:我承诺,从你发帖,以下问题:How to run spring boot without a web container?只需在非Web环境中启动Spring启动应用程序:new SpringApplicationBuilder() .sources(SpringBootApp.class) .web(false) .run(args)...

java – Spring Data Rest资源上的自定义链接【代码】

Spring Data Rest存储库指出可以将自定义链接添加到实体,如下所示: http://docs.spring.io/spring-data/rest/docs/current/reference/html/#_the_resourceprocessor_interface 示例给出:@Bean public ResourceProcessor<Resource<Person>> personProcessor() {return new ResourceProcessor<Resource<Person>>() {@Overridepublic Resource<Person> process(Resource<Person> resource) {resource.add(new Link("http://localhos...

java – 通过spring配置查询Cassandra查询【代码】

有什么简单的方法可以通过xml配置打开cassandra上的查询日志记录吗?我正在使用命名空间:xmlns:cassandra="http://www.springframework.org/schema/data/cassandra"但我找不到任何合适的解决方案.我试图通过cqlsh打开跟踪,但它不适用于我的应用程序. 我还试图添加线:<logger name="com.datastax.driver.core.QueryLogger.NORMAL" level="TRACE" />但也行不通. 我的版本:弹簧数据卡桑德拉-1.4.0cassandra:2.1.5解决方法:请查看此...