我无法获得验证工作.我有这个简单的端点,它是Spring Boot应用程序的一部分:
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response create(@Valid UserDTO userDTO, @Context UriInfo uriInfo) {
User user = UserParser.parse(userDTO);
userService.save(user);
final URI uri = uriInfo.getAbsolutePathBuilder().path(String.valueOf(user.getId())).build();
return Response.created(uri).build();
}
Run Code Online (Sandbox Code Playgroud)
然后,UserDTO验证:
@Getter
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserDTO {
private Long id;
// redundant validations, for testing
@NotNull
@Size(min = 5, max = 80, message = "First name too short")
@NotBlank(message = "First name blank")
@NotEmpty(message = "First name empty")
private String firstName;
@NotNull
@Size(min = 2, max = 80, message = "Last name …Run Code Online (Sandbox Code Playgroud) 我遇到了与这个问题相同的问题,使用Spring Boot 1.3.0而没有我的控制器注释@RestController,只是@Path和@Service.正如该问题中的OP所说,
对我来说,这不是明智的事
我也无法理解他们为什么会将它重定向到/ error.我很可能会遗漏一些东西,因为我只能向客户回馈404或200.
我的问题是他的解决方案似乎不适用于1.3.0,所以我有以下请求流:让我们说我的代码抛出一个NullPointerException.它将由我ExceptionMapper的一个人处理
@Provider
public class GeneralExceptionMapper implements ExceptionMapper<Throwable> {
private static final Logger LOGGER = LoggerFactory.getLogger(GeneralExceptionMapper.class);
@Override
public Response toResponse(Throwable exception) {
LOGGER.error(exception.getLocalizedMessage());
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
}
}
Run Code Online (Sandbox Code Playgroud)
我的代码返回500,但不是将其发送回客户端,而是尝试将其重定向到/ error.如果我没有其他资源,它将发回404.
2015-12-16 18:33:21.268 INFO 9708 --- [nio-8080-exec-1] o.glassfish.jersey.filter.LoggingFilter : 1 * Server has received a request on thread http-nio-8080-exec-1
1 > GET http://localhost:8080/nullpointerexception
1 > accept: */*
1 > host: localhost:8080
1 > …Run Code Online (Sandbox Code Playgroud) 我有一个Spring Boot和maven的小项目,现在我正在尝试配置logback来写入文件.我希望它写入一个给定的文件${project.build.directory}/${log.folder}/logfile.log,因此构建目录的子文件夹${log.folder}是我在application.properties文件中指定的属性,放在我的/resources文件夹下.
这是我的logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.boot" level="INFO"/>
<logger name="org.springframework.security" level="ERROR"/>
<logger name="org.glassfish.jersey" level="DEBUG"/>
<property resource="application.properties"/>
<appender name="DUMMY_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${project.build.directory}/${log.folder}/logfile.log</file>
<encoder>
<pattern>%d{"yyyy-MM-dd HH:mm:ss,SSS zzz"}, [%thread] %-5level %logger{5} - %msg%n
</pattern>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${log.folder}/spring.log.%d</fileNamePattern>
</rollingPolicy>
</appender>
<logger name="xxxxxx" level="INFO" additivity="false">
<appender-ref ref="DUMMY_APPENDER"/>
</logger>
<root level="INFO">
<appender-ref ref="DUMMY_APPENDER"/>
</root>
</configuration>
Run Code Online (Sandbox Code Playgroud)
它写日志,但我的问题是,当我运行应用程序时,它会创建一个文件夹project.build.directory_IS_UNDEFINED,然后将我的log.folder放在它下面.它在文档中说,那
作为其构建工具,logback依赖于Maven,这是一种广泛使用的开源构建工具.
当在logback.xml中,我开始键入$ {pro ...然后我的IDE显示一组可用的maven隐式属性.
所以它应该有效,但事实并非如此.知道为什么吗?
我面临与这个问题相同的情况,没有有用的答案。
当我向一对多关系的许多部分添加一个新元素时,Hibernate 会生成两个查询,一个用于插入,另一个用于更新父级的外键。
为什么需要第二个查询?不是在插入中设置了父级的 id 吗?有没有办法避免这种情况?
Hibernate:
/* insert mydomain.LanguageKnowledge */
insert
into
languageKnowledge
(language_fk, level_fk, personId_fk)
values
(?, ?, ?)
Hibernate:
/* create one-to-many row mydomain.Person.offeredLanguages */
update
languageKnowledge
set
personId_fk=?
where
id=?
public class LanguageKnowledge {
@Id
@GeneratedValue(strategy = IDENTITY)
private Integer id;
@Enumerated(STRING)
@Column(name = "language_fk")
private LanguageIso639_3 language;
@Enumerated(STRING)
@Column(name = "level_fk")
private LanguageLevel level;
protected LanguageKnowledge() {
}
}
public class Person {
@Id
@GeneratedValue(strategy = IDENTITY)
private Integer id;
@OneToMany(fetch = EAGER, …Run Code Online (Sandbox Code Playgroud) 我继承了一些代码,原来的开发人员已经没有人留下了。该代码大量使用了CompletableFuture,这是我第一次使用它,所以我仍在尝试理解它。据我了解, a(Completable)Future通常与某种多线程机制一起使用,该机制允许我们在执行耗时的任务时执行其他操作,然后只需通过 Future 获取其结果。正如javadoc中所示:
interface ArchiveSearcher { String search(String target); }
class App {
ExecutorService executor = ...
ArchiveSearcher searcher = ...
void showSearch(final String target) throws InterruptedException {
Future<String> future = executor.submit(new Callable<String>() {
public String call() {
return searcher.search(target);
}});
displayOtherThings(); // do other things while searching
try {
displayText(future.get()); // use future
} catch (ExecutionException ex) { cleanup(); return; }
}
}
Run Code Online (Sandbox Code Playgroud)
然而,在我继承的这个应用程序中,以下不使用任何多线程的模式多次出现:
public Object serve(Object input) throws ExecutionException, InterruptedException { …Run Code Online (Sandbox Code Playgroud) java ×4
spring-boot ×3
jersey ×2
asynchronous ×1
future ×1
hibernate ×1
jax-rs ×1
jersey-2.0 ×1
logback ×1
maven ×1
one-to-many ×1
properties ×1
spring ×1
validation ×1