use*_*872 5 maven spring-data-jpa spring-boot
我有一个使用 MySQL 作为后端的 spring boot(1.4.3.RELEASE) 应用程序。将 Spring Data 与 Oracle UCP 和 MySQL Java 连接用于连接池。现在,尝试将其移至多模块项目。因此我的项目结构如下。
parent project
|---pom.xml -> This is a parent pom.
|---common
|---pom.xml
|---src
|---model
|---pom.xml
|---src
|---service(Interface only)
|---pom.xml
|---src
|---service Impl(Implementations only)
|---pom.xml
|---src
|---repository(Spring Data)
|---pom.xml
|---src
|---web
|---pom.xml
|---src
Run Code Online (Sandbox Code Playgroud)
我的父 pom.xml 如下:
parent project
|---pom.xml -> This is a parent pom.
|---common
|---pom.xml
|---src
|---model
|---pom.xml
|---src
|---service(Interface only)
|---pom.xml
|---src
|---service Impl(Implementations only)
|---pom.xml
|---src
|---repository(Spring Data)
|---pom.xml
|---src
|---web
|---pom.xml
|---src
Run Code Online (Sandbox Code Playgroud)
Web 中的 Application.java:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<relativePath />
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.test</groupId>
<artifactId>test-parent</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>Test Project</name>
<description>Test components</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<version.spring.boot>1.4.3.RELEASE</version.spring.boot>
<version.mysql.connector>6.0.5</version.mysql.connector>
<version.slf4j>1.7.21</version.slf4j>
</properties>
<dependencyManagement>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<version>${version.spring.boot}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${version.slf4j}</version>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>cc-model</module>
<module>cc-common</module>
<module>cc-dbrepo</module>
<module>cc-dbservice</module>
<module>cc-dbserviceimpl</module>
<module>cc-web</module>
</modules>
</project>
Run Code Online (Sandbox Code Playgroud)
网络 pom.xml:
@SpringBootApplication(scanBasePackages =
{ "com.test.dbrepo.service.impl", "com.test.db.service", "com.test.dbrepo.repository" })
public class DialerApplication {
Run Code Online (Sandbox Code Playgroud)
在我的存储库 pom.xml 中,我有 spring-data
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>com.cc.dialer</groupId>
<artifactId>cc-dbservice</artifactId>
<version>${project.version}</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我的数据源代码和存储库在存储库项目中。我在 web 模块中有我的 Spring 安全代码,它通过注入使用服务模块。
启动 Web 模块应用程序时出现以下错误。
创建名为“webSecurityConfig”的 bean 时出错:通过字段“userDetailsService”表达的不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“userDetailsService”的 bean 时出错:通过字段“userService”表达的不满意的依赖;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的“com.cc.test.db.service.UserService”类型的合格 bean:预计至少有 1 个 bean 有资格作为自动装配候选。依赖注解:{@org.springframework.beans.factory.annotation.Autowired(required=true)}
是否缺少任何其他配置。
启动时未发现服务 impl 模块中的 Bean。
谢谢
小智 -1
根据您的配置,不会扫描 com.cc.test.db.service 包。
添加它。
您的注释应如下所示:
@SpringBootApplication(scanBasePackages =
{ "com.test.dbrepo.service.impl", "com.test.db.service", "com.test.dbrepo.repository", "com.cc.test.db.service" })
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3495 次 |
最近记录: |