我在sbt中设置了一个多模块项目,配置如下:
模块 signup
:Spring套2.4.4
模块 ui
:Spring5.4.5(非Spring套)
项目级 build.sbt
有以下内容 lazy val ui = (project in file("ui")).dependsOn(signup % "test->test;compile->compile")
我使用以下插件来构建war文件 addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.2.2")
的 ui
模块
问题是:当我在tomcat中部署ui模块的war文件时,它没有启动ui模块,而是启动signup模块(因为signup还有单独运行它的主类)
该项目使用较低版本的依赖项,如spring boot 2.1.2.RELEASE
使用最新版本的依赖项时的日志如下:
22-Mar-2021 15:45:22.116 INFO [Catalina-utility-1] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.4.4)
[WARN ] 2021-03-22 15:45:27.509 [Catalina-utility-1] AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
它失败了,因为它需要jdbc属性 application.properties
文件。但这是 signup
正在运行的模块,需要 jdbc
属性。理想情况下,它不应该在部署ui模块的war文件时启动,它只依赖于类/方法的注册模块。
请指导我应该以何种方式继续工作,以找到解决这个问题的办法。另外,如果你需要更多关于代码的信息,请告诉我。
更新:
如果我把这句话注解掉 main
注册模块的spring boot类,项目运行良好。现在我正在研究如何在执行 sbt package
用于创建war文件。
暂无答案!
目前还没有任何答案,快来回答吧!