【发布时间】:2017-05-31 23:20:20
【问题描述】:
我有一个以 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
我的父pom.xml如下:
<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>
Web 中的Application.java:
@SpringBootApplication(scanBasePackages =
{ "com.test.dbrepo.service.impl", "com.test.db.service", "com.test.dbrepo.repository" })
public class DialerApplication {
web pom.xml:
<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>
在我的存储库 pom.xml 中,我有 spring-data
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
我的数据源代码和存储库在存储库项目中。 我在 Web 模块中有我的 Spring 安全代码,它通过注入使用服务模块。
当我启动我的网络模块应用程序时出现以下错误。
创建名为“webSecurityConfig”的 bean 时出错:不满意 通过字段“userDetailsService”表示的依赖关系;嵌套的 例外是 org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名为“userDetailsService”的 bean 时出错:不满意 通过字段“userService”表示的依赖关系;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: 否 'com.cc.test.db.service.UserService' 类型的合格 bean 可用:预计至少有 1 个符合 autowire 条件的 bean 候选人。依赖注解: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
是否缺少其他配置。
启动时未发现服务实现模块中的 Bean。
谢谢
【问题讨论】:
-
您显示的 POM 不完整,因此我们无法在这里为您提供帮助。您缺少 SQL 数据源,您的驱动程序在哪里声明?在WAR运行中嵌入tomcat?还是spring-boot可执行jar中包含的jar?你的 mysql 驱动在 maven 中声明在哪里?
-
更新了我的帖子。
-
我会删除我的答案。我认为有一个误解,是由错误消息中的 "unsatisfied dependency" 字样引起的。可能您的 maven POM 是正确的,但是您的 Spring bean 定义存在问题。您应该在定义 Spring bean (Annotations ???) 的位置发布代码的基本部分。
-
用户服务在哪里?它包含在maven中吗?如果是,是否被spring正确扫描(自动扫描包)?
-
你好。我有完全相同的问题。最终解决您的问题的方法是什么?
标签: maven spring-boot spring-data-jpa