gpt4 book ai didi

java - 将 Maven 项目部署到 Tomcat 无法连接到 Postgres

转载 作者:行者123 更新时间:2023-11-28 22:47:12 26 4
gpt4 key购买 nike

我正在尝试将 .war 文件导入到 tomcat8。

到目前为止,即使启动了 Tomcat,我也无法访问我的 Web 应用程序的页面。我从这个命令 (systemctl status tomcat8.service) 得到这个错误:

Mar 11 11:34:25 osboxes tomcat8[48213]:     at org.postgresql.Driver.makeConnection(Driver.java:404)
Mar 11 11:34:25 osboxes tomcat8[48213]: at org.postgresql.Driver.connect(Driver.java:272)
Mar 11 11:34:25 osboxes tomcat8[48213]: at org.apache.tomcat.dbcp.dbcp2.DriverConnectionFactory.createConnection(DriverConnect
Mar 11 11:34:25 osboxes tomcat8[48213]: at org.apache.tomcat.dbcp.dbcp2.PoolableConnectionFactory.makeObject(PoolableConnectio
Mar 11 11:34:25 osboxes tomcat8[48213]: at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.validateConnectionFactory(BasicDataSou
Mar 11 11:34:25 osboxes tomcat8[48213]: at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createPoolableConnectionFactory(BasicD
Mar 11 11:34:25 osboxes tomcat8[48213]: ... 27 more
Mar 11 11:34:25 osboxes tomcat8[48213]: Starting service [Catalina]
Mar 11 11:34:25 osboxes tomcat8[48213]: Starting Servlet Engine: Apache Tomcat/8.5.34 (Ubuntu)
Mar 11 11:34:25 osboxes tomcat8[48213]: Deploying web application archive [/var/lib/tomcat8/webapps/slb.war]

几秒钟后:

Mar 11 11:25:02 osboxes tomcat8[47998]:     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
Mar 11 11:25:02 osboxes tomcat8[47998]: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
Mar 11 11:25:02 osboxes tomcat8[47998]: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
Mar 11 11:25:02 osboxes tomcat8[47998]: at java.lang.Thread.run(Thread.java:748)
Mar 11 11:25:02 osboxes tomcat8[47998]: Deployment of web application archive [/var/lib/tomcat8/webapps/slb.war] has finished in [
Mar 11 11:25:02 osboxes tomcat8[47998]: Deploying web application directory [/var/lib/tomcat8/webapps/ROOT]
Mar 11 11:25:02 osboxes tomcat8[47998]: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this
Mar 11 11:25:02 osboxes tomcat8[47998]: Deployment of web application directory [/var/lib/tomcat8/webapps/ROOT] has finished in [3
Mar 11 11:25:02 osboxes tomcat8[47998]: Starting ProtocolHandler ["http-nio-8080"]
Mar 11 11:25:02 osboxes tomcat8[47998]: Server startup in 7238 ms

顺便说一句,驱动程序所在的行以红色突出显示。

tomcat 库的内容:

osboxes@osboxes:~/hds-api-master$ 
ls /var/lib/tomcat8/lib/
–p postgresql-9.4.1212.jar

我来自哪里:

我将一个 java spring boot 应用程序导出到 .war 扩展名,没有错误,得到一个 .war 并将它移动到 tomcat 的 web 应用程序文件夹。我用于 maven 的命令:

mvn clean install
mvn package

它应该做什么:使用 URL 在端口 8080 上打开 Web 服务器:

localhost:8080/slb

编辑:我更改了 conf 文件中的密码,现在我的 tomcat 服务器显然运行良好,但显然我无法访问我的 webapp 或者我做错了,这是日志:

Systemctl;

tomcat8.service - Apache Tomcat 8.5 Web Application Server
Loaded: loaded (/lib/systemd/system/tomcat8.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2019-03-12 04:57:57 EDT; 2min 33s ago
Docs: https://tomcat.apache.org/tomcat-8.5-doc/index.html
Process: 59566 ExecStartPre=/usr/libexec/tomcat8/tomcat-update-policy.sh (code=exited, status=0/SUCCESS)
Main PID: 59582 (java)
Tasks: 34 (limit: 4653)
Memory: 363.9M
CGroup: /system.slice/tomcat8.service
└─59582 /usr/lib/jvm/java-8-openjdk-amd64//bin/java -Djava.util.logging.config.file=/var/lib/tomcat8/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms512m -Xmx1024m -XX:+UseConcMarkSweepGC -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/share/tomcat8/bin/bootstrap.jar:/usr/share/tomcat8/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat8 -Dcatalina.home=/usr/share/tomcat8 -Djava.io.tmpdir=/tmp org.apache.catalina.startup.Bootstrap start

Mar 12 04:58:07 osboxes tomcat8[59582]: 2019-03-12 04:58:07 [localhost-startStop-1] INFO o.s.o.j.LocalContainerEntityManagerFactoryBean - Initialized JPA EntityManagerFactory for persistence unit 'default'
Mar 12 04:58:08 osboxes tomcat8[59582]: 2019-03-12 04:58:08 [localhost-startStop-1] INFO o.h.h.i.QueryTranslatorFactoryInitiator - HHH000397: Using ASTQueryTranslatorFactory
Mar 12 04:58:10 osboxes tomcat8[59582]: 2019-03-12 04:58:10 [localhost-startStop-1] INFO o.s.j.e.a.AnnotationMBeanExporter - Registering beans for JMX exposure on startup
Mar 12 04:58:10 osboxes tomcat8[59582]: 2019-03-12 04:58:10 [localhost-startStop-1] INFO fr.thuasne.slb.hds.api.Application - Started Application in 8.473 seconds (JVM running for 12.378)
Mar 12 04:58:10 osboxes tomcat8[59582]: Deployment of web application archive [/var/lib/tomcat8/webapps/slb.war] has finished in [11,978] ms
Mar 12 04:58:10 osboxes tomcat8[59582]: Deploying web application directory [/var/lib/tomcat8/webapps/ROOT]
Mar 12 04:58:11 osboxes tomcat8[59582]: 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.
Mar 12 04:58:11 osboxes tomcat8[59582]: Deployment of web application directory [/var/lib/tomcat8/webapps/ROOT] has finished in [398] ms
Mar 12 04:58:11 osboxes tomcat8[59582]: Starting ProtocolHandler ["http-nio-8080"]
Mar 12 04:58:11 osboxes tomcat8[59582]: Server startup in 12692 ms

和 tomcat 日志文件:

12-Mar-2019 04:57:57.874 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/var/lib/tomcat8/common/classes], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.878 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/var/lib/tomcat8/common], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.878 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/usr/share/tomcat8/common/classes], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.879 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/usr/share/tomcat8/common], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.880 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/var/lib/tomcat8/server/classes], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.881 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/var/lib/tomcat8/server], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.881 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/usr/share/tomcat8/server/classes], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.881 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/usr/share/tomcat8/server], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.881 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/var/lib/tomcat8/shared/classes], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.882 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/var/lib/tomcat8/shared], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.882 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/usr/share/tomcat8/shared/classes], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:57.882 WARNING [main] org.apache.catalina.startup.ClassLoaderFactory.validateFile Problem with directory [/usr/share/tomcat8/shared], exists: [false], isDirectory: [false], canRead: [false]
12-Mar-2019 04:57:58.451 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.34 (Ubuntu)
12-Mar-2019 04:57:58.453 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Sep 20 2018 08:12:50 UTC
12-Mar-2019 04:57:58.454 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number: 8.5.34.0
12-Mar-2019 04:57:58.455 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
12-Mar-2019 04:57:58.455 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.18.0-10-generic
12-Mar-2019 04:57:58.456 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
12-Mar-2019 04:57:58.457 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-8-openjdk-amd64/jre
12-Mar-2019 04:57:58.458 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_191-8u191-b12-2ubuntu0.18.10.1-b12
12-Mar-2019 04:57:58.460 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
12-Mar-2019 04:57:58.461 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /var/lib/tomcat8
12-Mar-2019 04:57:58.462 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/share/tomcat8
12-Mar-2019 04:57:58.463 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/var/lib/tomcat8/conf/logging.properties
12-Mar-2019 04:57:58.465 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
12-Mar-2019 04:57:58.466 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xms512m
12-Mar-2019 04:57:58.466 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Xmx1024m
12-Mar-2019 04:57:58.467 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -XX:+UseConcMarkSweepGC
12-Mar-2019 04:57:58.468 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
12-Mar-2019 04:57:58.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
12-Mar-2019 04:57:58.469 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
12-Mar-2019 04:57:58.470 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
12-Mar-2019 04:57:58.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/var/lib/tomcat8
12-Mar-2019 04:57:58.471 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/share/tomcat8
12-Mar-2019 04:57:58.473 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/tmp
12-Mar-2019 04:57:58.473 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.17] using APR version [1.6.3].
12-Mar-2019 04:57:58.474 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
12-Mar-2019 04:57:58.475 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
12-Mar-2019 04:57:58.480 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1 11 Sep 2018]
12-Mar-2019 04:57:58.649 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
12-Mar-2019 04:57:58.668 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
12-Mar-2019 04:57:58.683 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 774 ms
12-Mar-2019 04:57:58.938 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
12-Mar-2019 04:57:58.940 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.34 (Ubuntu)
12-Mar-2019 04:57:58.976 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/var/lib/tomcat8/webapps/slb.war]
12-Mar-2019 04:58:01.308 INFO [localhost-startStop-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.
12-Mar-2019 04:58:10.956 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/var/lib/tomcat8/webapps/slb.war] has finished in [11,978] ms
12-Mar-2019 04:58:10.957 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/var/lib/tomcat8/webapps/ROOT]
12-Mar-2019 04:58:11.351 INFO [localhost-startStop-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.
12-Mar-2019 04:58:11.355 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/var/lib/tomcat8/webapps/ROOT] has finished in [398] ms
12-Mar-2019 04:58:11.364 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
12-Mar-2019 04:58:11.376 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 12692 ms

已解决:

对于最后一个问题,我需要使用 http://127.0.0.1:8080/ 而不是本地主机访问 tomcat

感谢您的帮助和时间。

最佳答案

从您的帖子中不清楚到底是什么问题,因为您只发布了部分异常。您发布的日志条目来自 Systemd,其中仅包含部分 Tomcat 日志。查找 Tomcat 日志,默认情况下在 $CATALINA_BASE/logs 中。

如果问题确实是缺少驱动程序,您可以通过将驱动程序复制到 $CATALINA_BASE/lib 目录来确认 - 重新启动 Tomcat 以使更改生效。

如果确实是这种情况,并且您想使用您的应用程序部署 PG-JDBC jar,那么使用 Maven 可以通过不同的方式来实现,例如maven-dependency-plugin , 或将其添加到资源目录并使用 Maven maven-resources-plugin .

关于java - 将 Maven 项目部署到 Tomcat 无法连接到 Postgres,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55105477/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com