我有一个关于 Spring Roo 2 M3 的工作项目。我意识到除了我在启动项目时创建的查找器之外,我还需要一个新的查找器。 我在 roo 控制台中生成了查找器:
finder add --entity ~.domain.Usuario --name findByUsername
它在 java 存储库中创建了正确的注释
@RooFinder("findByUsername")
以及存储库方面的方法
public abstract Page<Usuario> UsuarioRepository.findByUsername(String username, Pageable pageable);
但它没有在服务中生成该查找器,也没有像我之前生成的其他查找器那样在服务实现中生成该查找器。
我在谷歌上搜索了几天,并尝试自己修复它,但没有取得任何进展。
<小时/>注意:几个月前,我在其他 spring roo 2 M3 项目中已经发生过这种情况。我遇到了同样的问题大约一周,然后经过多次随机篡改代码后,最终 roo 控制台触发了更改,但我不明白为什么它会起作用。
<小时/>编辑: log.roo
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-06 18:32:01
project setup --topLevelPackage ar.edu.um.ingsoftware --projectName "umbook"
jpa setup --database MYSQL --provider HIBERNATE --hostName 127.0.0.1 --databaseName umbook --userName root
entity jpa --class ~.reference.Persona --abstract
field string --fieldName username --notNull
field string --fieldName password --notNull
entity jpa --class ~.domain.Usuario --extends ~.reference.Persona
field string --fieldName email --notNull
field string --fieldName nombre --notNull
field string --fieldName apellido --notNull
field date --fieldName fechaNacimiento --type java.util.Calendar --past
entity jpa --class ~.domain.Administrador --extends ~.reference.Persona
entity jpa --class ~.domain.Comentario
field string --fieldName contenido --notNull
field reference --fieldName autor --type ~.domain.Usuario
field date --fieldName timestmp --type java.util.Calendar
repository jpa --all
finder add --name findByEmailEquals --entity ~.domain.Usuario
finder add --name findByNombreLike --entity ~.domain.Usuario
finder add --name findByApellidoLike --entity ~.domain.Usuario
service --all
web mvc setup
web mvc view setup --type THYMELEAF
web mvc controller --all --responseType THYMELEAF
// script --file script_roo
exit
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-06 18:32:26
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-06 18:57:39
web mvc finder --all --responseType THYMELEAF --pathPrefix 'find'
web mvc language --code es --useAsDefault
web mvc templates setup --type THYMELEAF
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-06 19:23:08
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-06 19:23:31
focus --class ~.domain.Usuario
field list --fieldName comentarios --type ~.domain.Comentario --mappedBy listaDeComentarios --cardinality ONE_TO_MANY
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-06 19:41:26
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-06 19:41:37
exit
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-06 19:42:18
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-06 19:42:36
focus --class ~.domain.Comentario
focus --class ~.domain.Usuario
// [failed] field list --fieldName comentariosHechos --type ~.domain.Comentario --mappedBy autor --cardinality ONE_TO_MANY
// [failed] field list --fieldName comentarios --type ~.domain.Comentario
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-06 19:53:59
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-06 19:54:16
focus --class ~.domain.Usuario
field list --fieldName comentarios --type ~.domain.Comentario
focus --class ~.domain.Comentario
focus --class ~.domain.Usuario
field list --fieldName comentarios --type ~.domain.Comentario --cardinality MANY_TO_MANY
field list --fieldName comentarios --type ~.domain.Comentario
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-06 19:58:35
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-06 19:58:50
// [failed] field list --fieldName comentariosHechos --type ~.domain.Comentario --mappedBy autor
focus --class ~.domain.Usuario
field list --fieldName comentariosHechos --type ~.domain.Comentario --mappedBy autor
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-06 23:36:33
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-16 18:03:39
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-19 04:51:01
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-24 20:40:34
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-24 20:42:02
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-24 20:42:15
help
project scan now
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-25 00:49:54
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-25 00:50:07
project scan status
project scan now
finder add --entity ~.domain.Usuario --name findByUsername
project scan now
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-26 04:59:57
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-26 05:00:09
project scan now
project scan now
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-26 05:12:02
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-26 05:12:13
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-26 05:15:11
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-26 05:16:30
project scan status
project scan status
project scan now
help
metadata status
help
version
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-26 05:36:24
// Spring Roo 2.0.0.M3 [rev 20a0f71] log opened at 2017-02-26 19:59:43
// Spring Roo 2.0.0.M3 [rev 20a0f71] log closed at 2017-02-26 20:59:20
<小时/>
EDIT2:插入后添加了 UsuarioRepository.java
package ar.edu.um.ingsoftware.repository;
import ar.edu.um.ingsoftware.domain.Usuario;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooJpaRepository;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.roo.addon.layers.repository.jpa.annotations.RooFinder;
@Transactional(readOnly = true)
/**
* = UsuarioRepository
*
* TODO Auto-generated class documentation
*
*/
@RooJpaRepository(entity = Usuario.class, finders = { @RooFinder("findByEmailEquals"), @RooFinder("findByNombreLike"), @RooFinder("findByApellidoLike"), @RooFinder("findByUsername") })
public interface UsuarioRepository extends JpaRepository<Usuario, Long>, UsuarioRepositoryCustom {
/**
* TODO Auto-generated method documentation
*
* @param email
* @param pageable
* @return Page
*/
public abstract Page<Usuario> findByEmailEquals(String email, Pageable pageable);
/**
* TODO Auto-generated method documentation
*
* @param email
* @return Long
*/
public abstract long countByEmailEquals(String email);
/**
* TODO Auto-generated method documentation
*
* @param nombre
* @param pageable
* @return Page
*/
public abstract Page<Usuario> findByNombreLike(String nombre, Pageable pageable);
/**
* TODO Auto-generated method documentation
*
* @param nombre
* @return Long
*/
public abstract long countByNombreLike(String nombre);
/**
* TODO Auto-generated method documentation
*
* @param apellido
* @param pageable
* @return Page
*/
public abstract Page<Usuario> findByApellidoLike(String apellido, Pageable pageable);
/**
* TODO Auto-generated method documentation
*
* @param apellido
* @return Long
*/
public abstract long countByApellidoLike(String apellido);
/**
* TODO Auto-generated method documentation
*
* @param username
* @param pageable
* @return Page
*/
public abstract Page<Usuario> findByUsername(String username, Pageable pageable);
/**
* TODO Auto-generated method documentation
*
* @param username
* @return Long
*/
public abstract long countByUsername(String username);
}
最佳答案
分析您的问题后,当包含新的查找器时,Spring Roo 2.0.0.M3 元数据监听器的一些问题似乎会影响服务生成。
这个问题已在 Spring Roo 2.0.0.RC1 中修复,很快就会发布。
无论如何,如果您push-in
了findByUsername
方法,服务接口(interface)和服务实现必须包含它。
如果您有任何问题,请告诉我!
希望对你有帮助
关于java - 新查找器不生成实现(M3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42475787/