这是我的堆栈:
- Micronaut 1.3.2
- Java 8
- Eclipse STS 4
Pom.xml 摘录:
<dependency>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-jdbc-hikari</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-hibernate-jpa</artifactId>
</dependency>
<dependency>
<groupId>io.micronaut.configuration</groupId>
<artifactId>micronaut-hibernate-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<path>
<groupId>io.micronaut.data</groupId>
<artifactId>micronaut-data-processor</artifactId>
<version>1.0.0.M1</version>
</path>
我的仓库:
import io.micronaut.data.annotation.Repository;
import io.micronaut.data.repository.CrudRepository;
@Repository
public interface UsuarioRepository extends CrudRepository<UsuarioModel, Long> { }
我的服务:
private UsuarioDTO atualizar(UsuarioDTO usuario) {
UsuarioModel modelo = new UsuarioModel();
modelo.setIdade(usuario.idade);
modelo.setNick(usuario.nick);
modelo.setNome(usuario.nome);
modelo.setPassword(usuario.password);
this.usuarioRepository.update(modelo);
return usuario;
}
应用程序.yml:
micronaut:
application:
name: micronaut-chatroom
server:
cors:
enabled: true
datasources:
default:
url: jdbc:h2:mem:devDb
driverClassName: org.h2.Driver
username: sa
password: ''
schema-generate: CREATE_DROP
dialect: H2
jpa:
default:
entity-scan:
packages: 'com.cr.model'
当我在我的 Micronaut 项目上运行安装 maven 命令时,出现错误:
[错误] 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project micronaut-chatroom: Compilation failure [ERROR] Unable to implement Repository method: UsuarioRepository.更新(对象实体)。未找到可能的实现。
有人经历过吗?
提前致谢!
编辑
这是我的 UsuarioModel 课程
@Entity(name = "Usuario")
@Table(name = "usuario")
public class UsuarioModel implements Serializable {
/**
*
*/
private static final long serialVersionUID = -7468837154917949190L;
@Id
@GeneratedValue
private Long id;
private String nome;
private String nick;
private String idade;
private String password;
@OneToMany
private List<MensagemModel> mensagens;
//Getter/Setters ommited
}
还有我的 MensagemModel 类:
@Entity(name = "Mensagem")
@Table(name = "mensagem")
public class MensagemModel implements Serializable {
/**
*
*/
private static final long serialVersionUID = 7634793331670289187L;
@Id
@GeneratedValue
private Long id;
@CreationTimestamp
private LocalDateTime data;
private String conteudo;
@ManyToOne
@JoinColumn(name = "usuario_id")
private UsuarioModel usuario;
//Getter/Setter ommited
}