gpt4 book ai didi

java.lang.NoClassDefFoundError : com/google/inject/servlet/GuiceServletContextListener 错误

转载 作者:行者123 更新时间:2023-11-28 22:53:14 27 4
gpt4 key购买 nike

<分区>

我正在尝试将 Guice 4.0 用于 Tomcat 8 的 Web 应用程序。我尝试从 wiki 做示例,但我在 Tomcat Localhost 日志中收到此错误:

    28-Nov-2015 16:36:26.136 SEVERE [RMI TCP Connection(3)-127.0.0.1] org.apache.catalina.core.StandardContext.listenerStart Error configuring application listener of class com.nirus.guice_confige.MyGuiceServletConfig
java.lang.NoClassDefFoundError: com/google/inject/servlet/GuiceServletContextListener
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoaderBase.findClassInternal(WebappClassLoaderBase.java:2496)
...

这是我的 web.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
version="3.1">
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<listener>
<listener-class>com.nirus.guice_confige.MyGuiceServletConfig</listener-class>
</listener>

</web-app>

还有我的 Guice 配置文件:

public class MyGuiceServletConfig extends GuiceServletContextListener {
@Override
protected Injector getInjector() {
return Guice.createInjector(new ServletModule(){
@Override
protected void configureServlets() {
serve("/JoinLobby").with(JoinLobby.class);
serve("/UpdateLobby").with(UpdateLobby.class);
bind(ILobby.class).to(Lobby.class);
}
});
}
}

UPD1:这是我的 Maven 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>NiRus</groupId>
<artifactId>ImagServerApp</artifactId>
<version>0.0.1-FirstStep</version>

<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>4.0</version>
</dependency>
</dependencies>
</project>

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