我正在建立一个Spring Boot maven多模块项目,其中有Domain层,Persistence层和Web层。
我一直在寻找类似的问题,但似乎不是我的情况,我怀疑这是由于该项目被分为多个独立的Maven模块,Spring无法找到该bean。
尝试了一些可能的解决方案,但它们似乎并没有解决问题。
library(networkD3)
# example data
data(MisLinks)
data(MisNodes)
# creating the plot
forceNetwork(Links = MisLinks, Nodes = MisNodes,
Source = "source", Target = "target",
Value = "value", NodeID = "name",
Group = "group", opacity = 1, fontSize = 15,
opacityNoHover = 0)
@SpringBootApplication(scanBasePackages = { "com.imricki.movie.domain", "com.imricki.movie.persistence",
"com.imricki.movie.web" })
public class SpringBootAplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootAplication.class, args);
}
}
@RequestMapping(value = "/api")
@RestController
class MovieRestController {
@Autowired
private MovieService service;
@RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
ResponseEntity<Void> delete(@PathVariable Long Id) {
this.service.delete(Id);
return new ResponseEntity<>(HttpStatus.OK);
}
@Service
public class MovieServiceImpl implements MovieService {
@Autowired
MovieRepository repo;
/** The model mapper to convert. */
private final ModelMapper modelMapper = new ModelMapper();
@Override
@Transactional
public void delete(Long id) {
this.repo.deleteById(id);
}
这是结构的样子
正如我之前认为的那样,我得到了启动该嵌入式Tomcat的机会,因为它找不到服务,因此无法注入bean
@Repository
public interface MovieRepository extends JpaRepository<Movie, Long> {
}
答案 0 :(得分:0)
似乎主要问题是缺少MovieRepository实现
Caused by: java.lang.ClassNotFoundException: com.imricki.movie.persistence.repository.MovieRepository
您未提供pom.xml,因此无法验证所有依赖项是否正确,但我怀疑您可能缺少@EnableJpaRepositories annotation
有关此注释here和此SO question
的更多信息示例:
@Configuration
@EnableJpaRepositories("com.acme.repositories")
class ApplicationConfiguration {
@Bean
EntityManagerFactory entityManagerFactory() {
// …
}
}
答案 1 :(得分:0)
我通过在主类中添加组件扫描解决了这个问题
@SpringBootApplication(scanBasePackages = { "com" })
@EntityScan(basePackages = { "com" })
public class SpringBootAplication {
public static void main(String[] args) throws Exception {
SpringApplication.run(SpringBootAplication.class, args);
}
}
通过这种方式,spring在扫描组件的所有maven模块中都有一个通用的基本软件包。
答案 2 :(得分:0)
您需要扫描软件包。通过添加@componentScan批注