Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot Spring引导组件扫描在maven多模块项目中不起作用_Spring Boot_Maven - Fatal编程技术网

Spring boot Spring引导组件扫描在maven多模块项目中不起作用

Spring boot Spring引导组件扫描在maven多模块项目中不起作用,spring-boot,maven,Spring Boot,Maven,我遵循了spring官方项目指南,以下是我的项目。当我使用/mvnw安装&&./mvnw-spring-boot:run-pl-user运行其中一个模块时,它失败了,出现以下日志 ... 2019-12-20 13:33:58.886 INFO 8830 --- [ restartedMain] n.j.scip.user.api.ScipApplication : Starting ScipApplication on jagger-mbp with PID 8830 (/U

我遵循了spring官方项目指南,以下是我的项目。当我使用
/mvnw安装&&./mvnw-spring-boot:run-pl-user
运行其中一个模块时,它失败了,出现以下日志

...
2019-12-20 13:33:58.886  INFO 8830 --- [  restartedMain] n.j.scip.user.api.ScipApplication        : Starting ScipApplication on jagger-mbp with PID 8830 (/Users/jagger/projects/jaggerwang/spring-cloud-in-practice/user/target/classes started by jagger in /Users/jagger/projects/jaggerwang/spring-cloud-in-practice/user)
2019-12-20 13:33:58.890  INFO 8830 --- [  restartedMain] n.j.scip.user.api.ScipApplication        : No active profile set, falling back to default profiles: default
2019-12-20 13:33:58.930  INFO 8830 --- [  restartedMain] o.s.b.devtools.restart.ChangeableUrls    : The Class-Path manifest attribute in /Users/jagger/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jaxb-runtime-2.3.2.jar referenced one or more files that do not exist: file:/Users/jagger/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.xml.bind-api-2.3.2.jar,file:/Users/jagger/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/txw2-2.3.2.jar,file:/Users/jagger/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/istack-commons-runtime-3.0.8.jar,file:/Users/jagger/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/stax-ex-1.8.1.jar,file:/Users/jagger/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/FastInfoset-1.2.16.jar,file:/Users/jagger/.m2/repository/org/glassfish/jaxb/jaxb-runtime/2.3.2/jakarta.activation-api-1.2.1.jar
2019-12-20 13:33:58.930  INFO 8830 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2019-12-20 13:33:58.931  INFO 8830 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2019-12-20 13:33:59.109  WARN 8830 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
2019-12-20 13:33:59.235 ERROR 8830 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:156) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:544) ~[spring-context-5.2.1.RELEASE.jar:5.2.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:141) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
    at net.jaggerwang.scip.user.api.ScipApplication.main(ScipApplication.java:48) ~[classes/:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) ~[spring-boot-devtools-2.2.1.RELEASE.jar:2.2.1.RELEASE]
Caused by: org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getWebServerFactory(ServletWebServerApplicationContext.java:203) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:179) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:153) ~[spring-boot-2.2.1.RELEASE.jar:2.2.1.RELEASE]
    ... 12 common frames omitted

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  13.211 s
[INFO] Finished at: 2019-12-20T13:33:59+08:00
[INFO] ------------------------------------------------------------------------
如果我在配置中提供一个
ServletWebServerFactory
bean,它会抱怨找不到其他bean

。。。
@豆子
公共ServletWebServerFactory ServletWebServerFactory(){
返回新的TomcatServletWebServerFactory();
}
...
这是我的申请表:

package net.jaggerwang.scip.user.api;
导入javax.sql.DataSource;
导入com.oembedler.moon.graphql.boot.GraphQLWebsocketAutoConfiguration;
导入net.jaggerwang.scip.user.api.config.ScipConfig;
导入org.flywaydb.core.Flyway;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.boot.ApplicationArguments;
导入org.springframework.boot.ApplicationRunner;
导入org.springframework.boot.DefaultApplicationArguments;
导入org.springframework.boot.WebApplicationType;
导入org.springframework.boot.autoconfigure.springboot应用程序;
导入org.springframework.boot.autoconfigure.domain.EntityScan;
导入org.springframework.boot.builder.SpringApplicationBuilder;
导入org.springframework.data.jpa.repository.config.EnableJpaRepositories;
导入lombok.extern.slf4j.slf4j;
@SpringBootApplication(scanBasePackages=“net.jaggerwang.scip.user”,
排除={GraphQLWebsocketAutoConfiguration.class})
@EntityScan(“net.jaggerwang.scip.user.adapter.repository.jpa.entity”)
@EnableJpaRepositories(“net.jaggerwang.scip.user.adapter.repository.jpa”)
@Slf4j
公共类ScipApplication实现ApplicationRunner{
公共枚举AppType{
WEB、DB_迁移
}
私有静态AppType AppType=AppType.WEB;
@自动连线
私有数据源;
公共静态void main(字符串[]args){
var appags=新的默认应用程序参数(args);
if(appags.getOptionValues(“app.type”)!=null
&&!appags.getOptionValues(“app.type”).isEmpty()){
appType=appType.valueOf(appags.getOptionValues(“app.type”).get(0.toUpperCase());
}
新的SpringApplicationBuilder(ScipConfig.class)
.web(appType==appType.web?WebApplicationType.SERVLET:WebApplicationType.NONE)
.run(args);
}
@凌驾
公共void运行(ApplicationArguments参数)引发异常{
if(appType==appType.DB\u迁移){
migrateDatabase(args);
}
}
私有void migrateDatabase(应用程序参数){
var flyway=flyway.configure().dataSource(dataSource.load();
flyway.migrate();
log.info(“迁移数据库完成”);
}
}

我还尝试直接使用
@ComponentScan
,它有相同的结果。

它似乎与在main类中使用
SpringApplicationBuilder
有关。如果我将main类更改为最简单的类,它运行正常

package net.jaggerwang.scip.user.api;
导入com.oembedler.moon.graphql.boot.GraphQLWebsocketAutoConfiguration;
导入org.springframework.boot.SpringApplication;
导入org.springframework.boot.autoconfigure.springboot应用程序;
导入org.springframework.boot.autoconfigure.domain.EntityScan;
导入org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication(scanBasePackages=“net.jaggerwang.scip.user”,
排除={GraphQLWebsocketAutoConfiguration.class})
@EntityScan(“net.jaggerwang.scip.user.adapter.repository.jpa.entity”)
@EnableJpaRepositories(“net.jaggerwang.scip.user.adapter.repository.jpa”)
公共类SCIP应用程序{
公共静态void main(字符串[]args){
run(ScipApplication.class,args);
}
}

Tomcat的一个JAR在下载时可能已被Maven损坏。尝试清除Maven的缓存并重建应用程序。