我试图使用Java 8新的日期模式而不是Joda,我有以下问题:
都
ZonedDateTime.parse("02/05/16 11:51.12.083 +04:30", DateTimeFormatter.ofPattern("dd/MM/yy HH:mm.ss.SSS Z"))
Run Code Online (Sandbox Code Playgroud)
和
LocalDateTime.parse("02/05/16 11:51.12.083 +04:30", DateTimeFormatter.ofPattern("dd/MM/yy HH:mm.ss.SSS Z"))
Run Code Online (Sandbox Code Playgroud)
抛出'java.time.format.DateTimeParseException'异常.而
org.joda.time.DateTime.parse("02/05/16 11:51.12.083 +04:30", DateTimeFormat.forPattern("dd/MM/yy HH:mm.ss.SSS Z"))
Run Code Online (Sandbox Code Playgroud)
工作良好.
异常的原因是:
java.time.format.DateTimeParseException:无法在索引22处解析文本'02/05/16 11:51.12.083 +04:30'
难道我做错了什么?
我使用以下(这看起来很像这个)代码下载文件:
@RequestMapping(value = "/tunes/{file_name}", method = RequestMethod.GET)
public void downloadTune(@PathVariable(value = "file_name") String tuneId,
HttpServletResponse response) {
perfomanceLogger.trace("=== Start retrieving tune with id: " + tuneId);
try {
String location = "";
// try {
location = resourceManagementService.getArtifcatByIdAndType(tuneId,
ControllerConstants.TYPE_MP3);
String pathSeparator = File.separator;
if (location == null || location.equals("")) {// load the default
// tune
location = System.getProperties().get("jboss.server.base.dir")
+ pathSeparator + ServicesConstants.FILE_LOCATION
+ pathSeparator + "ringtone_1.mp3";
if (!new File(location).exists()) {
location = "";
}
}
if (!location.equals("")) { …Run Code Online (Sandbox Code Playgroud) controller spring-mvc download spring-security illegalstateexception
我需要使用url中的令牌ID(或者可能在请求标头中)对一些休息服务进行身份验证 - 但这对于现在来说并不重要.我正在尝试使用java配置来设置它作为这篇文章的指南.我的问题是我不知道如何处理从提供程序验证失败时引发的"BadCredentialsException".这是我的安全配置:
public static class SecurityConfigForRS extends
WebSecurityConfigurerAdapter {
@Autowired
TokenAuthenticationProvider tokenAuthenticationProvider;
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.authenticationProvider(tokenAuthenticationProvider);
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean()
throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.regexMatcher("^/rest.*")
.addFilterBefore(
new TokenAuthenticationFilter(
authenticationManagerBean()),
AbstractPreAuthenticatedProcessingFilter.class)
.and().csrf().disable();
}
}
Run Code Online (Sandbox Code Playgroud)
现在我跳过其他实现 - 如果它有帮助我将在以后发布它们.
当令牌丢失或无效时,TokenAuthernticationProvider抛出a BadCredentialsException.我需要抓住这个并发回一个401-Unauthorized.是否有可能做到这一点?
我们已将Spring Boot从1.2.4升级到1.5.8,自动将Hibernate从4.3.10升级到5.0.12.我们正面临一些Hibernate问题,我们希望使用此版本的Spring Boot,但将Hibernate降级回4.3.10.
Spring Boot 1.5.8与Hibernate 4.3.10兼容吗?
我得到:
线程“main” org.joda.time.IllegalFieldValueException 中的异常:无法解析“1444-05-31 10-10”:dayOfMonth 的值 31 必须在 [1,30] 范围内
代码是:
Chronology hijri = IslamicChronology.getInstanceUTC();
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH-mm")
.withChronology(hijri);
DateTime hijriDt = formatter.parseDateTime("1444-05-31 10-10");
Run Code Online (Sandbox Code Playgroud)
我在某处读到 joda 从 0 而不是 01 开始计算月份。但是,这是用户输入,需要通过格式化程序进行解析。我不能使用 joda 的常规 setter 和 getter 来设置日期。