尝试结合@Async和@EventListener注释启用异步事件处理,但我仍然看到侦听器在发布线程中运行.
您可以在此处找到示例:
@SpringBootApplication
@EnableAsync
class AsyncEventListenerExample {
static final Logger logger = LoggerFactory.getLogger(AsyncEventListenerExample.class);
@Bean
TaskExecutor taskExecutor() {
return new SimpleAsyncTaskExecutor();
}
static class MedicalRecordUpdatedEvent {
private String id;
public MedicalRecordUpdatedEvent(String id) {
this.id = id;
}
@Override
public String toString() {
return "MedicalRecordUpdatedEvent{" +
"id='" + id + '\'' +
'}';
}
}
@Component
static class Receiver {
@EventListener
void handleSync(MedicalRecordUpdatedEvent event) {
logger.info("thread '{}' handling '{}' event", Thread.currentThread(), event);
}
@Async
@EventListener
void handleAsync(MedicalRecordUpdatedEvent event) …Run Code Online (Sandbox Code Playgroud) 当我包含actuator并启用debug日志消息时,会有大量Did not find handler method for日志消息.
2015-08-14 18:34:25.335 DEBUG 94889 --- [nio-8080-exec-5] o.s.b.a.e.mvc.EndpointHandlerMapping : Looking up handler method for path /index.html
2015-08-14 18:34:25.336 DEBUG 94889 --- [nio-8080-exec-5] o.s.b.a.e.mvc.EndpointHandlerMapping : Did not find handler method for [/index.html]
Run Code Online (Sandbox Code Playgroud)
当我删除时,actuator这些日志消息消失.
我尝试过Spring Boot 1.2.5和1.3.0.M3版本,它的工作方式相同.通过spring initializr使用using web和actuatordependencies 生成项目很容易尝试.
你知道原因是什么吗?
谢谢.
我有以下域对象:
@Entity
public class Item {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@OneToMany
private List<PropertyDefinition> propertyDefinitions;
}
@Entity
public class PropertyDefinition {
@Id
private Long id;
private final String name;
private final String value;
}
Run Code Online (Sandbox Code Playgroud)
我想对项目进行排序,例如名为PropertyDefinition.value的"title"
我怎么能用Spring Data JPA做到这一点?
Iterable<Item> items = itemRepository.findAll(new Sort("???"));
Run Code Online (Sandbox Code Playgroud)
示例代码可以在这里找到:https:
//github.com/altfatterz/sort-poc/
任何反馈意见.
我有一个带有数组字段的文档
"chapters": [
{ "id" : "14031871223912313", ...}
...
]
Run Code Online (Sandbox Code Playgroud)
我想使用以下命令查询使用Spring Data的MongoTemplate返回id:
class Chapter {
private String id;
public String getId() {
return id;
}
}
Run Code Online (Sandbox Code Playgroud)
这样就不会填充id.我尝试使用@Field中描述的不同映射选项http://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mapping.conventions.id-field
我究竟做错了什么?我知道我总是可以回到mongo java驱动程序,但我认为这应该工作.
在此先感谢您的帮助.
spring ×2
asynchronous ×1
hibernate ×1
jpa ×1
mongodb ×1
mongodb-java ×1
sorting ×1
spring-boot ×1
spring-data ×1