当我尝试在TomCat上部署并执行使用Spring的应用程序时,为什么我会获得此异常?

时间:2015-07-03 11:55:18

标签: java spring tomcat derby spring-jdbc

我不是很喜欢 Maven NetBeans (过去我使用过Eclipse和Ant),我在尝试在TomCat上部署和执行Web时遇到以下问题使用Spring的应用程序。

我使用名为来自Archetype的项目 Maven 功能获取了一个项目,并选择了从教程中指定的原型(名为 entando-archetype-portal的原型) -bootstrap ,这是一个生成Entando门户的原型。)

在下一个NetBeans窗口中,我将项目名称指定为 myfirstportal ,并将 ID指定为 com.entando

我没有更改默认项目路径:

/home/andrea/NetBeansProjects/myfirstportal

然后,在NetBeans项目选项卡中,我选择了我的项目,然后执行Maven 清理和构建任务,该任务可以运行几秒钟,并以构建成功正确结束消息。

所以看起来构建过程没问题。

然后我选择我的项目并执行Run,所以我选择 TomCat 安装。

启动过程开始但最后我总是收到此错误消息:

ebapp assembled in [9582 msecs]
Building war: /home/andrea/NetBeansProjects/myfirstportal/target/myfirstportal.war

--- tomcat7-maven-plugin:2.1:exec-war-only (war-build-standalone) @ myfirstportal ---
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Total time: 31.067s
Finished at: Thu Jul 02 18:23:41 CEST 2015
Final Memory: 48M/233M
------------------------------------------------------------------------
NetBeans: Deploying on Apache Tomcat or TomEE
    profile mode: false
    debug mode: false
    force redeploy: true
Checking data source definitions for missing JDBC drivers...
Undeploying ...
undeploy?path=/myfirstportal
OK - Undeployed application at context path /myfirstportal
In-place deployment at /home/andrea/NetBeansProjects/myfirstportal/target/myfirstportal
Deployment is in progress...
deploy?config=file%3A%2Ftmp%2Fcontext5305066681099450691.xml&path=/myfirstportal
FAIL - Deployed application at context path /myfirstportal but context failed to start

正如您在最后看到的那样,该过程因以下特定错误消息而失败:

FAIL - Deployed application at context path /myfirstportal but context failed to start

所以我调查了进一步打开NetBeans 服务窗口右键单击Tomcat服务器并选择查看服务器日志,在这里我获得了应该导致失败的异常:< / p>

03-Jul-2015 13:33:40.806 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log No Spring WebApplicationInitializer types detected on classpath
03-Jul-2015 13:33:41.546 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log Initializing Spring root WebApplicationContext
03-Jul-2015 13:33:52.989 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.listenerStart Exception sending context initialized event to listener instance of class org.entando.entando.aps.servlet.StartupListener
 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'InitializerManager' defined in class path resource [spring/baseSystemConfig.xml]: Invocation of init method failed; nested exception is java.lang.Exception: Error while initializating Db Installer
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
................................................................
................................................................
................................................................
Caused by: java.lang.Exception: Error while initializating Db Installer
    at org.entando.entando.aps.system.init.InitializerManager.init(InitializerManager.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
................................................................
................................................................
................................................................
Caused by: java.lang.RuntimeException: Error while loading component installation report - version: production
    at org.entando.entando.aps.system.init.InstallationReportDAO.loadReport(InstallationReportDAO.java:58)
    at org.entando.entando.aps.system.init.AbstractInitializerManager.extractReport(AbstractInitializerManager.java:40)
    ... 66 more
Caused by: com.agiletec.aps.system.exception.ApsSystemException: Error getting connection to the datasource
    at com.agiletec.aps.system.common.AbstractDAO.getConnection(AbstractDAO.java:64)
    at org.entando.entando.aps.system.init.InstallationReportDAO.loadReport(InstallationReportDAO.java:40)
    ... 67 more
Caused by: java.sql.SQLException: Cannot load JDBC driver class 'org.apache.derby.jdbc.EmbeddedDriver'
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2043)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createDataSource(BasicDataSource.java:1939)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.getConnection(BasicDataSource.java:1412)
    at com.agiletec.aps.system.common.AbstractDAO.getConnection(AbstractDAO.java:61)
    ... 68 more
Caused by: java.lang.ClassNotFoundException: org.apache.derby.jdbc.EmbeddedDriver
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1305)
    at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1157)
    at org.apache.tomcat.dbcp.dbcp2.BasicDataSource.createConnectionFactory(BasicDataSource.java:2034)
    ... 71 more

03-Jul-2015 13:35:54.960 INFO [http-nio-8080-exec-14] org.apache.catalina.core.ApplicationContext.log Closing Spring root WebApplicationContext

似乎它可能依赖于某些数据库连接问题

可能是什么问题?我错过了什么?我该如何解决它?

TNX

编辑1:

所以在我看来,进入我的NetBeans项目的 Dependencies 文件夹(包含Maven下载所有jar的那个)我确实没有 derby-10 .xxxjar 文件但是进入 pom.xml 文件我引用了 detby驱动程序类

<properties>
    <!--
    <test.database.driver>org.postgresql.Driver</test.database.driver>
    <test.database.hostname>localhost</test.database.hostname>
    <test.database.port>5432</test.database.port>
    <test.database.username>agile</test.database.username>
    <test.database.password>agile</test.database.password>
    <test.database.port.url>jdbc:postgresql://${test.database.hostname}:${test.database.port}/${project.artifactId}testPort</test.database.port.url>
    <test.database.serv.url>jdbc:postgresql://${test.database.hostname}:${test.database.port}/${project.artifactId}testServ</test.database.serv.url>
    -->
    <!--
    <test.database.driver>com.mysql.jdbc.Driver</test.database.driver>
    <test.database.hostname>localhost</test.database.hostname>
    <test.database.port>3306</test.database.port>
    <test.database.username>root</test.database.username>
    <test.database.password>agile</test.database.password>
    <test.database.port.url>jdbc:mysql://${test.database.hostname}:${test.database.port}/${project.artifactId}testPort</test.database.port.url>
    <test.database.serv.url>jdbc:mysql://${test.database.hostname}:${test.database.port}/${project.artifactId}testServ</test.database.serv.url>
    -->
    <test.database.driver>org.apache.derby.jdbc.EmbeddedDriver</test.database.driver>
    <test.database.hostname>localhost</test.database.hostname>
    <test.database.port>1527</test.database.port>
    <test.database.username>agile</test.database.username>
    <test.database.password>agile</test.database.password>
    <test.database.port.url>jdbc:derby:${project.build.directory}/test/db/${project.artifactId}testPort;create=true</test.database.port.url>
    <test.database.serv.url>jdbc:derby:${project.build.directory}/test/db/${project.artifactId}testServ;create=true</test.database.serv.url>

    <skipDerby>true</skipDerby>
    <skipStandalone>true</skipStandalone>
    <entando.version>4.2.0-TP1</entando.version>
    <spring.version>4.0.6.RELEASE</spring.version>
    <struts2.version>2.3.16.3</struts2.version>
    <cxf.version>3.0.0-milestone2</cxf.version>
</properties>

正如您所看到的,与 postgresql MySql DBMS相关的部分是禁用的,而是与 org.apache.derby.jdbc.EmbeddedDriver相关的部分似乎已启用。

进入依赖部分,我发现:

<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derby</artifactId>
    <version>10.9.1.0</version>
</dependency>

<dependency>
    <groupId>org.apache.derby</groupId>
    <artifactId>derbyclient</artifactId>
    <version>10.9.1.0</version>
</dependency>

所以我认为Maven应该正确下载和配置德比驱动程序类。

为什么看起来这个罐子没有下载?

3 个答案:

答案 0 :(得分:1)

没有找到驱动程序。在tomcat的情况下 - 将驱动程序jar放入libs文件夹并尝试再次启动它。

编辑:您提供依赖项的方式,它仅在编译时可用,但不会在生成的战争中可用。我认为你应该使用类似assembly-pluginshade-plugin的东西,以便在战争中提供这个jar。

但是,如果您查看tomcat文档... ta-daaa - (搜索单词forget) - 您应该将驱动程序jar提供给lib文件夹

答案 1 :(得分:1)

将maven依赖项添加到java构建路径将解决您的错误。

转到添加库并在java构建路径菜单中选择maven依赖项。

答案 2 :(得分:0)

您需要{class 1}} derby download到您的类路径/ lib。