我有一个多模块项目,但我的配置有问题.我在包nl.example.hots.boot中有一个主要方法
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan(basePackages = {"nl.*"})
@EntityScan("nl.*")
public class HotsApplication {
public static void main(String[] args) {
SpringApplication.run(HotsApplication.class, args);
}
Run Code Online (Sandbox Code Playgroud)
在nl.example.hots.core.*包中我有类:
@Service
@AllArgsConstructor
@Transactional(propagation = Propagation.REQUIRED)
public class MapImportService {
private MapInputModelMapper mapInputModelMapper;
private MapEntityRepository mapEntityRepository;
public void add(final MapInputModel mapInputModel) {
System.out.println(mapInputModel.getName());
mapEntityRepository.save(mapInputModelMapper.mapToEntiy(mapInputModel));
}
Run Code Online (Sandbox Code Playgroud)
和:
@Component
@Mapper
public interface MapInputModelMapper {
MapInputModel mapToInputModel(final MapEntity n);
MapEntity mapToEntiy(final MapInputModel n);
}
Run Code Online (Sandbox Code Playgroud)
存储库位于包nl.example.hots.persistence中.*
运行应用程序时出现以下错误:
Description:
Parameter 0 of constructor in nl.example.hots.core.dataimport.MapImportService.MapImportService required a bean of type 'nl.timonschultz.hots.core.map.mapper.MapInputModelMapper' that could not be …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,我有一个英雄实体。我还希望能够返回每个英雄ID和名称的列表。我得到它与此工作:
@Repository
public interface HeroEntityRepository extends JpaRepository<HeroEntity, Long> {
@Query("select s.id, s.name from HEROES s")
List<Object> getIdAndName();
}
// in controller:
@GetMapping
public List<Object> getHeroNames() {
return heroEntityRepository.getIdAndName();
}
Run Code Online (Sandbox Code Playgroud)
我在另一篇文章中尝试了用接口替换Object的建议,但是随后我收到了一个空值列表([{{name“:null,” id“:null},{” name“:null,” id“ :null},//等)。自定义界面:
public interface HeroNameAndId {
Long getId();
String getName();
}
Run Code Online (Sandbox Code Playgroud)
当创建仅具有ID和名称值的Entity时,我收到了“ ConverterNotFoundException”。我不确定正确的方法是。我有它与对象一起工作,但这似乎不是很干净。
我的HeroEntity:
@Getter
@Builder
@Entity(name = "HEROES")
@AllArgsConstructor
public class HeroEntity extends HasId<Long> {
private String name;
private String shortName;
private String attributeId;
@ElementCollection private List<String> translations;
@OneToOne(cascade = CascadeType.ALL) private HeroIconEntity icon;
private String role; …Run Code Online (Sandbox Code Playgroud)