小编Pet*_*iev的帖子

spring-boot中的多个conversionServices

我有一个启动应用程序,并在我的一个外观我尝试Autowire conversionService这样:

@Autowired
private ConversionService conversionService;
Run Code Online (Sandbox Code Playgroud)

结果我得到了这个:

Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.springframework.core.convert.ConversionService] is defined: expected single matching bean but found 3: mvcConversionService,defaultConversionService,integrationConversionService
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1061)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:949)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
... 16 more
Run Code Online (Sandbox Code Playgroud)

为了克服这个问题,我添加了一个限定符lilke:

@Autowired
@Qualifier("mvcConversionService")
private ConversionService c;
Run Code Online (Sandbox Code Playgroud)

这一切都有效.但是我的所有自定义转换器都会自动添加到mvcConversionService.现在我想扩展ConversionService并添加另一种方法,但我的转换器再次添加到mvcConversionService.有没有办法告诉spring-boot conversionService使用哪些来自动注册我的转换器?我不想手动将所有转换器列入新的转换器conversionService.

spring-boot

8
推荐指数
1
解决办法
4019
查看次数

Spring批处理作业实例已存在

好,

我知道以前曾经问过,但我仍然无法找到我的问题的明确答案.我的问题是:我使用spring批处理将数据导出到SOLR搜索服务器.它需要每分钟运行一次,因此我可以导出所有更新.第一次执行通过OK,但第二次执行抱怨:

2014-10-02 20:37:00,022 [defaultTaskScheduler-1] ERROR: catching
org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job     instance already exists and is complete for parameters={catalogVersionPK=3378876823725152,
type=UPDATE}.  If you want to run this job again, change the parameters.
    at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:126)
    at 
Run Code Online (Sandbox Code Playgroud)

当然,我可以像这样在作业中添加日期时间参数:

.addLong("time", System.getCurrentTimeMillis())
Run Code Online (Sandbox Code Playgroud)

然后这个工作可以多次运行.但是,我也想查询作业的最后一次执行,所以我有这样的代码:

DateTime endTime = new DateTime(0);
JobExecution je = jobRepository.getLastJobExecution("searchExportJob", new JobParametersBuilder().addLong("catalogVersionPK", catalogVersionPK).addString("type", type).toJobParameters());
if (je != null && je.getEndTime() != null) {
   endTime = new DateTime(je.getEndTime());
}
Run Code Online (Sandbox Code Playgroud)

这没有任何回报,因为我没有提供时间参数.所以看起来我可以运行一次并获得最后一次执行时间,或者我可以多次运行它而不是上次执行时间.我真的被卡住了:(

spring spring-batch

7
推荐指数
2
解决办法
2万
查看次数

更新到Spring-security-3.2.0.RC2时的AuthenticationManager

我最近更新了RC1的spring-security-3.2.0.RC2,并根据博客文章删除了QUIESCENT_POST_PROCESSOR.在我以前创建一个AuthenticationManager bean之前,如下所示:

@Bean(name = {"defaultAuthenticationManager", "authenticationManager"})
public AuthenticationManager defaultAuthenticationManager() throws Exception {
    return new AuthenticationManagerBuilder(null).userDetailsService(context.getBean(MyUserDetailsService.class)).passwordEncoder(new Md5PasswordEncoder()).and().build();
}
Run Code Online (Sandbox Code Playgroud)

所以我把它改成了:

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws BeansException, Exception {
    auth.userDetailsService(context.getBean(MyUserDetailsService.class)).passwordEncoder(new Md5PasswordEncoder());
}
Run Code Online (Sandbox Code Playgroud)

但不幸的是我再也无法掌握AuthenticationManager了.我也是这样创建RememberMeAuthenticationFilter:

@Bean(name = { "defaultRememberMeAuthenticationFilter", "rememberMeAuthenticationFilter" })
protected RememberMeAuthenticationFilter defaultRememberMeAuthenticationFilter() throws Exception {
    return new RememberMeAuthenticationFilter(defaultAuthenticationManager(), context.getBean(DefaultRememberMeServices.class));
}
Run Code Online (Sandbox Code Playgroud)

所以你可以看到我需要掌握AuthenticationManager,但我不知道如何???

spring-security

6
推荐指数
1
解决办法
1万
查看次数

如何使用Spring Data JPA查询Map值?

所以我的数据库模型是这样的:我有Stores,每个Store都有一个本地化的名称.所以我选择将本地化名称表示为Map:

public class Store {
   private Map<Locale,LocalizedValue> name;
}
Run Code Online (Sandbox Code Playgroud)

你可以看到这是一个地图<Locale, LocalizedValue>,其中LocalizedValue是这样一类:

@Embeddable
public class LocalizedValue {

   @Column(name = "value")
   private String value;
}
Run Code Online (Sandbox Code Playgroud)

这一切都很棒.但是我遇到了一个问题,我想查询我的Spring Data JPA存储库并查找具有给定英文名称的所有商店.所以我的存储库方法如下所示:

Store findByName(Map.Entry<Locale, LocalizedValue> name);
Run Code Online (Sandbox Code Playgroud)

但它抛出了这个异常:

 2014-10-07 23:49:55,862 [qtp354231028-165] ERROR: Parameter value [en=Some Value] did not match expected type [com.test.LocalizedValue(n/a)]; nested exception is java.lang.IllegalArgumentException: Parameter value [en=Some Value] did not match expected type [com.test.LocalizedValue (n/a)]
org.springframework.dao.InvalidDataAccessApiUsageException: Parameter value [en=Some Value] did not match expected type …
Run Code Online (Sandbox Code Playgroud)

java spring jpa spring-data spring-data-jpa

6
推荐指数
1
解决办法
2万
查看次数

Spring 验证注解顺序

我想问一下是否可以在 Spring 中明确设置验证顺序。我的意思是,我有这个命令对象:

public class UserData {
 @NotBlank
 private String newPassword;

 @NotBlank
 private String confirmPassword;

 @Email(applyIf="email is not blank")
 @NotBlank
 private String email;

 @NotBlank
 private String firstName = "";

 private String middleName = "";

 @NotBlank
 private String lastName = "";

        // getters/setters
}
Run Code Online (Sandbox Code Playgroud)

我在页面顶部显示我的错误消息,如下所示:

<spring:hasBindErrors name="${userData}">
   <ul class="errors">
      <c:forEach items="${errors.allErrors}" var="error">
       <li><spring:message message="${error}"/></li>
   </c:forEach>
  </ul>
</spring:hasBindErrors>
Run Code Online (Sandbox Code Playgroud)

问题是不管我的错误消息是按以下顺序显示的:

* Fill you last name.
* Fill you password.
* Fill your emailaddress.
* Fill you password again.
* Select your gender.
* …
Run Code Online (Sandbox Code Playgroud)

java validation spring annotations

5
推荐指数
1
解决办法
5221
查看次数

禁用 Spring Batch 作业

我想知道是否有办法以编程方式启用/禁用所有定义的 spring-batch 作业?例如,当我部署我的应用程序时,数据库是空的,此时我的作业正在运行并抛出异常。我想禁用作业,直到在数据库中填充一些数据(直到出现某些表)。这可能吗?

spring-batch

2
推荐指数
1
解决办法
7355
查看次数

为什么javax.money.CurrencyUnit不能序列化?

为什么不javax.money.CurrencyUnit延伸java.io.Serializable?它的所有子类实现java.io.Serializable,并且最重要的是,如果你想在你的hibernate映射中使用它,那么findbugs会阻止你(非常正确)因为:

[INFO] Class com.mycompany.SiteEntity defines non-transient non-serializable instance field defaultCurrency [com.mycompany.SiteEntity] In SiteEntity.java
[INFO] Class com.mycompany.SiteEntity defines non-transient non-serializable instance field supportedCurrencies [com.mycompany.SiteEntity] In SiteEntity.java
[INFO] Class com.mycompany.UserEntity defines non-transient non-serializable instance field sessionCurrency [com.mycompany.UserEntity] In UserEntity.java
Run Code Online (Sandbox Code Playgroud)

这是否意味着必须JDKCurrencyAdapter在一个人的hibernate映射中使用该类?我更喜欢使用界面,但如果不可能,那么我将使用该类.

java hibernate jsr354 java-money

1
推荐指数
1
解决办法
376
查看次数