gpt4 book ai didi

java - 无法部署项目

转载 作者:行者123 更新时间:2023-12-01 12:41:10 25 4
gpt4 key购买 nike

我有通过正确配置的监听器类配置的数据库连接 在DD中

    <web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

<listener>
<listener-class>contpack.startL</listener-class>
</listener>
<context-param>
<param-name>username</param-name>
<param-value>root</param-value>
</context-param>
<context-param>
<param-name>password</param-name>
<param-value>root</param-value>
</context-param>
<context-param>
<param-name>url</param-name>
<param-value>jdbc:mysql://localhost:3306/mysql</param-value>
</context-param>

<servlet>
<servlet-name>hell</servlet-name>
<servlet-class>com.contpack.Dbc</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hell</servlet-name>
<url-pattern>/Dbc</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>home.html</welcome-file>
</welcome-file-list>
</web-app>

但我仍然无法部署项目,服务器日志显示未找到 startL.java 监听器类,这是为什么,因为配置与名称正确监听器类是:

        package com.contpack;

import javax.servlet.*;
import javax.servlet.http.*;
import model.Database;


public class startL implements ServletContextListener {

public void contextInitialized(ServletContextEvent event)
{
ServletContext sc = event.getServletContext();
String url = sc.getInitParameter("url");
String user_name = sc.getInitParameter("username");
String password = sc.getInitParameter("password");
// String database = sc.getInitParameter("database");
Database db = new Database(url,user_name,password);
//System.out.println("in the listener!!");
sc.setAttribute("db", db);

}

public void contextDestroyed(ServletContextEvent event)
{

}
}

服务器日志的堆栈跟踪是:

    [2014-08-01T20:53:59.112+0530] [glassfish 4.0] [SEVERE] [] [javax.enterprise.system.core] 
[tid: _ThreadID=34 _ThreadName=admin-listener(3)]
[timeMillis: 1406906639112] [levelValue: 1000]
[[Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: contpack.startL.java]]

如果我删除监听器标记,则应用程序运行正常

最佳答案

...
<listener>
<listener-class>contpack.startL</listener-class>
</listener>
...

并且您的监听器在包中

package com.contpack;

这意味着您的监听器完全限定名称是

com.contpack.startL

因此设置正确的监听器类会有所帮助。您的 web.xml 应如下所示

...
<listener>
<listener-class>com.contpack.startL</listener-class>
</listener>
...

遵循 java 命名约定始终是一个好主意

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

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