Spring Boot在部署到Tomcat期间无法加载外部jar
Posted
技术标签:
【中文标题】Spring Boot在部署到Tomcat期间无法加载外部jar【英文标题】:Spring Boot Cannot load External jar during deployment to Tomcat 【发布时间】:2015-01-06 00:32:12 【问题描述】:我在 Spring boot 1.2 上使用嵌入式服务器(使用 spring boot 应用程序运行)和添加到类路径的外部 jar(数据库驱动程序 Postgis)很好地工作。但是当我尝试在 Eclipse 中的 TomCat 8 上部署和运行它时。我收到了这个错误Cannot load driver class: org.postgis.DriverWrapper
请帮忙
janv. 06, 2015 12:08:03 AM org.apache.catalina.core.StandardService startInternal
INFO: Démarrage du service Catalina
janv. 06, 2015 12:08:03 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.15
janv. 06, 2015 12:08:04 AM org.apache.jasper.servlet.TldScanner scanJars
INFO: 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.
janv. 06, 2015 12:08:08 AM org.apache.catalina.core.ApplicationContext log
INFO: Spring WebApplicationInitializers detected on classpath: [org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration@44692e7f, com.geopro.config.ApplicationInitializer@556bb6ef]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.2.0.RELEASE)
2015-01-06 00:08:08.751 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletConfigInitParams] PropertySource with lowest search precedence
2015-01-06 00:08:08.756 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletContextInitParams] PropertySource with lowest search precedence
2015-01-06 00:08:08.757 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [jndiProperties] PropertySource with lowest search precedence
2015-01-06 00:08:08.757 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemProperties] PropertySource with lowest search precedence
2015-01-06 00:08:08.758 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemEnvironment] PropertySource with lowest search precedence
2015-01-06 00:08:08.758 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
2015-01-06 00:08:08.822 INFO --- [ost-startStop-1] o.s.boot.SpringApplication : Starting application on hp-PC with PID 6564 (C:\Users\hp\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\geopro\WEB-INF\lib\spring-boot-1.2.0.RELEASE.jar started by hp in C:\eclipse)
2015-01-06 00:08:08.895 INFO --- [ost-startStop-1] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@745df3a9: startup date [Tue Jan 06 00:08:08 GMT 2015]; root of context hierarchy
2015-01-06 00:08:08.902 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Replacing [servletContextInitParams] PropertySource with [servletContextInitParams]
2015-01-06 00:08:10.266 INFO --- [ost-startStop-1] o.s.b.f.s.DefaultListableBeanFactory : Overriding bean definition for bean 'beanNameViewResolver': replacing [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/ErrorMvcAutoConfiguration$WhitelabelErrorViewConfiguration.class]] with [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter; factoryMethodName=beanNameViewResolver; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]]
2015-01-06 00:08:10.691 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [applicationConfig: [classpath:/application.properties]] PropertySource with search precedence immediately lower than [applicationConfigurationProperties]
2015-01-06 00:08:10.691 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Removing [applicationConfigurationProperties] PropertySource
2015-01-06 00:08:10.692 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Removing [defaultProperties] PropertySource
2015-01-06 00:08:11.111 INFO --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration' of type [class org.springframework.boot.autoconfigure.dao.PersistenceExceptionTranslationAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-01-06 00:08:11.209 INFO --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$6051c0dc] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-01-06 00:08:11.249 INFO --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'transactionAttributeSource' of type [class org.springframework.transaction.annotation.AnnotationTransactionAttributeSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-01-06 00:08:11.268 INFO --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'transactionInterceptor' of type [class org.springframework.transaction.interceptor.TransactionInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-01-06 00:08:11.281 INFO --- [ost-startStop-1] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.config.internalTransactionAdvisor' of type [class org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2015-01-06 00:08:11.311 INFO --- [ost-startStop-1] o.a.c.c.C.[.[localhost].[/demoweb] : Initializing Spring embedded WebApplicationContext
2015-01-06 00:08:11.311 DEBUG --- [ost-startStop-1] o.s.web.context.ContextLoader : Published root WebApplicationContext as ServletContext attribute with name [org.springframework.web.context.WebApplicationContext.ROOT]
2015-01-06 00:08:11.311 INFO --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 2416 ms
2015-01-06 00:08:11.869 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletConfigInitParams] PropertySource with lowest search precedence
2015-01-06 00:08:11.869 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletContextInitParams] PropertySource with lowest search precedence
2015-01-06 00:08:11.870 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [jndiProperties] PropertySource with lowest search precedence
2015-01-06 00:08:11.870 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemProperties] PropertySource with lowest search precedence
2015-01-06 00:08:11.870 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemEnvironment] PropertySource with lowest search precedence
2015-01-06 00:08:11.870 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
2015-01-06 00:08:11.955 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletConfigInitParams] PropertySource with lowest search precedence
2015-01-06 00:08:11.955 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletContextInitParams] PropertySource with lowest search precedence
2015-01-06 00:08:11.955 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [jndiProperties] PropertySource with lowest search precedence
2015-01-06 00:08:11.956 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemProperties] PropertySource with lowest search precedence
2015-01-06 00:08:11.956 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemEnvironment] PropertySource with lowest search precedence
2015-01-06 00:08:11.956 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
2015-01-06 00:08:12.027 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletConfigInitParams] PropertySource with lowest search precedence
2015-01-06 00:08:12.027 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [servletContextInitParams] PropertySource with lowest search precedence
2015-01-06 00:08:12.028 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [jndiProperties] PropertySource with lowest search precedence
2015-01-06 00:08:12.028 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemProperties] PropertySource with lowest search precedence
2015-01-06 00:08:12.028 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Adding [systemEnvironment] PropertySource with lowest search precedence
2015-01-06 00:08:12.028 DEBUG --- [ost-startStop-1] o.s.w.c.s.StandardServletEnvironment : Initialized StandardServletEnvironment with PropertySources [servletConfigInitParams,servletContextInitParams,jndiProperties,systemProperties,systemEnvironment]
2015-01-06 00:08:12.949 INFO --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2015-01-06 00:08:12.952 INFO --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'errorPageFilter' to: [/*]
2015-01-06 00:08:12.953 INFO --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2015-01-06 00:08:12.953 INFO --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2015-01-06 00:08:13.177 WARN --- [ost-startStop-1] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: org.postgis.DriverWrapper
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1202)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
AppConfig.java
package com.geopro.config;
import javax.persistence.EntityManagerFactory;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.orm.jpa.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.vendor.HibernateJpaSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableAutoConfiguration
@ComponentScan(basePackages = "com.geopro" )
//@Import( DomainAndPersistenceConfig.class )
@EnableJpaRepositories(basePackages = "com.geopro.repositories" )
@EntityScan(basePackages = "com.geopro.entities" )
@EnableTransactionManagement
public class AppConfig
@Bean
public HibernateJpaSessionFactoryBean sessionFactory(EntityManagerFactory emf)
HibernateJpaSessionFactoryBean factory = new HibernateJpaSessionFactoryBean();
factory.setEntityManagerFactory(emf);
return factory;
ApplicationInitializer.java
package com.geopro.config;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
public class ApplicationInitializer extends SpringBootServletInitializer
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application)
return application.sources(AppConfig.class);
application.properties
spring.datasource.driverClassName=org.postgis.DriverWrapper
spring.datasource.url=jdbc:postgresql_postGIS://localhost:5432/geopro
spring.datasource.username=postgres
spring.datasource.password=***********
spring.jpa.database-platform=org.hibernate.spatial.dialect.postgis.PostgisDialect
spring.jpa.show-sql=true
编辑 1 类路径的JConsole
VM arguments:
-Dosgi.requiredJavaVersion=1.6 -Xms512m -Xmx1024m
Class path:
C:\eclipse\\plugins/org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
Library path:
C:\ProgramData\Oracle\Java\javapath;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\ProgramData\Oracle\Java\javapath;C:\Users\hp\bin\Sencha\Cmd\5.0.1.231;C:\PYTHON27\ARCGIS10.1\LIB\SITE-PACKAGES\PYQT4;C:\PROGRAM FILES (X86)\EAZFUSCATOR.NET;C:\jdk\BIN;C:\WINDOWS\SYSTEM32;C:\WINDOWS;C:\WINDOWS\SYSTEM32\WBEM;C:\WINDOWS\SYSTEM32\WINDOWSPOWERSHELL\V1.0\;C:\PROGRAM FILES\WIDCOMM\BLUETOOTH SOFTWARE\;C:\PROGRAM FILES\WIDCOMM\BLUETOOTH SOFTWARE\SYSWOW64;;C:\PROGRAM FILES (X86)\MICROSOFT SQL SERVER\100\TOOLS\BINN\;C:\PROGRAM FILES\MICROSOFT SQL SERVER\100\TOOLS\BINN\;C:\PROGRAM FILES\MICROSOFT SQL SERVER\100\DTS\BINN\;C:\PYTHON26\ARCGIS10.0;C:\PYTHON26\ARCGIS10.0\SCRIPTS;C:\PYTHON27\ARCGIS10.1;C:\WAMP\BIN\php\PHP5.4.3;C:\USERS\HP\DOCUMENTS\VISUAL STUDIO 2010\PROJECTS\GEODATA\GEODATA\BIN\DEBUG\GEODATA.EXE;C:\F\G77\BIN;C:\ADT-BUNDLE-WINDOWS\SDK\PLATFORM-TOOLS;C:\ADT-BUNDLE-WINDOWS\SDK\TOOLS;C:\apache-ant\BIN;C:\PROGRAM FILES (X86)\HEROKU\BIN;C:\PROGRAM FILES (X86)\GIT\CMD;C:\APACHE-MAVEN\BIN;C:\PYTHON27\ARCGIS10.1\SCRIPTS;C:\USERS\HP\DOWNLOADS\ECLIPSE-STANDARD-KEPLER-SR1-WIN32-X86_64\ECLIPSE\PLUGINS\COM.GOOGLE.GWT.ECLIPSE.SDKBUNDLE_2.6.0\GWT-2.6.0;;.
Boot class path:
C:\Program Files\Java\jre1.8.0_25\lib\resources.jar;C:\Program Files\Java\jre1.8.0_25\lib\rt.jar;C:\Program Files\Java\jre1.8.0_25\lib\sunrsasign.jar;C:\Program Files\Java\jre1.8.0_25\lib\jsse.jar;C:\Program Files\Java\jre1.8.0_25\lib\jce.jar;C:\Program Files\Java\jre1.8.0_25\lib\charsets.jar;C:\Program Files\Java\jre1.8.0_25\lib\jfr.jar;C:\Program Files\Java\jre1.8.0_25\classes
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.testpg</groupId>
<artifactId>demoweb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demoweb</name>
<description>Demo project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.0.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<start-class>demoweb.Application</start-class>
<java.version>1.7</java.version>
<geotools.version>12-RC1</geotools.version>
</properties>
<repositories>
<repository>
<id>lambdaj</id>
<name>Lambdaj Repository</name>
<url>http://lambdaj.googlecode.com/svn/repo/releases/</url>
</repository>
<repository>
<id>sonatype-postgis-releases</id>
<name>Sonatype Postgis Releases Repo</name>
<url>http://oss.sonatype.org/content/repositories/postgis-releases</url>
</repository>
<repository>
<id>OSGEO GeoTools repo</id>
<url>http://download.osgeo.org/webdav/geotools</url>
</repository>
<repository>
<id>Hibernate Spatial repo</id>
<url>http://www.hibernatespatial.org/repository</url>
</repository>
<repository>
<id>maven2-repository.dev.java.net</id>
<name>Java.net repository</name>
<url>http://download.java.net/maven/2</url>
</repository>
<repository>
<id>osgeo</id>
<name>Open Source Geospatial Foundation Repository</name>
<url>http://download.osgeo.org/webdav/geotools/</url>
</repository>
<repository>
<snapshots>
<enabled>true</enabled>
</snapshots>
<id>boundless</id>
<name>Boundless Maven Repository</name>
<url>http://repo.boundlessgeo.com/main</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.googlecode.lambdaj</groupId>
<artifactId>lambdaj</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-spatial</artifactId>
<version>4.3</version>
<exclusions>
<exclusion>
<artifactId>hibernate-core</artifactId>
<groupId>org.hibernate</groupId>
</exclusion>
<exclusion>
<artifactId>postgis-jdbc</artifactId>
<groupId>org.postgis</groupId>
</exclusion>
<exclusion>
<artifactId>postgresql</artifactId>
<groupId>postgresql</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.geotools</groupId>
<artifactId>gt-geojson</artifactId>
<version>$geotools.version</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1100-jdbc41</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.grundid.opendatalab</groupId>
<artifactId>geojson-jackson</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
【问题讨论】:
你确定这个类在你在图片中提到的那些罐子里吗? 是的,我确定,它已经使用“spring boot app”成功运行 你能检查正在运行的应用程序的类路径吗? 请问如何检查正在运行的应用程序的类路径? 你应该去你的eclipse项目属性中的部署程序集(在你发布的图片中选择项目的2级)并将maven依赖jar添加到部署环境中。 【参考方案1】:如果您的构建类路径中有该库,这并不意味着您在运行应用程序的类路径中也有它。一种方法(从我的角度来看更好的方法)是 geogeek 描述并将库打包到战争档案中的方法。另一种方法是将 jar 库复制到 Tomcat 的 /lib 文件夹中。
希望对你有帮助!
【讨论】:
【参考方案2】:解决此问题的最佳方法是add the jar in internal Maven repository (like in this post),以避免管理类路径及其令人头疼的问题,因此所有 jar 都打包在 war 文件中。
【讨论】:
我知道这是一个旧线程,但是如果我想要一个“附加组件”库怎么办?这是不可能的吗?例如,我创建了一个带有嵌入式 tomcat 的引导应用程序 jar/war 文件,然后另一个团队具有稍后出现的附加功能。我希望原始二进制文件保持不变,而其他团队只需将 lib 添加到“附加组件”并重新启动。 @peekay 你有想过这个吗?我想做一个类似的概念... 不,我从来没有为这个项目做这个,现在我已经转向另一个机会。以上是关于Spring Boot在部署到Tomcat期间无法加载外部jar的主要内容,如果未能解决你的问题,请参考以下文章
spring boot 部署war 到tomcat上面静态资源无法访问
将 Spring Boot 战争部署到 Tomcat 服务器并收到“无法启动嵌入式 Tomcat org.springframework.context.ApplicationContextExcep
无法在外部 tomcat 上部署 Spring Boot 应用程序