gpt4 book ai didi

hibernate - java.lang.ClassNotFoundException : javax. ws.rs.client.RxInvokerProvider 异常

转载 作者:行者123 更新时间:2023-11-28 21:55:41 36 4
gpt4 key购买 nike

我正在尝试使用 loginServlet 从 jsp 页面登录。它重定向到 servlet,但它不进行身份验证并抛出错误。这是代码:

JSP 文件:

<div class="container">
<div class="row">
<div class="box">
<div class="col-md-6 col-md-offset-4">

<h2 class="intro-text">Welcome! Login here:</h2>


<form class="form-horizontal" action="LoginServlet" method="POST">
<div class="form-group">
<label class="control-label col-sm-2" for="username">Username:</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="username" placeholder="Enter username" name="un">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="pwd">Password:</label>
<div class="col-sm-4">
<input type="password" class="form-control" id="pwd" placeholder="Enter password" name="pwd">
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<div class="checkbox">
<label><input type="checkbox" name="remember"> Remember me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-4">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>

</div>
</div>
</div>

登录服务小程序:

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {


try
{

User user = new User();
user.setUsername(request.getParameter("un"));
user.setPassword(request.getParameter("pwd"));

PrintWriter writer = response.getWriter();

// build HTML code
String htmlRespone = "<html>";
htmlRespone += "<h2>Your username is: " + user.getUsername() + "<br/>";
htmlRespone += "Your password is: " + user.getPassword() + "</h2>";
htmlRespone += "</html>";

writer.println(htmlRespone);

if (authUser(user))
{
System.out.println("exists!");
HttpSession session = request.getSession(true);
session.setAttribute("currentSessionUser",user);
response.sendRedirect("home.jsp"); //logged-in page
}

else {
System.out.println("not!");
response.sendRedirect("invalidLogin.jsp"); //error page
}

}


catch (Throwable theException)
{
System.out.println(theException);
}
}

public boolean authUser(User user) {
// TODO Auto-generated method stub
User userDB = UserDAO.getUserByUsername(user.getUsername());
System.out.println(userDB.getUsername()+" "+userDB.getPassword());
System.out.println(user.getUsername()+" "+user.getPassword());

if (userDB != null && userDB.getUsername().equals(user.getUsername()) && userDB.getPassword().equals(user.getPassword())) {
return true;
} else {
return false;
}
}

}

UserDAO 中的 getUserByUsername 方法:

public static User getUserByUsername(String username) {

Session session = factory.openSession();
Transaction tx = null;
List<User> users = null;

tx = session.beginTransaction();
Query query = session.createQuery("FROM User WHERE username = :username ");
query.setParameter("username", username);
List<User> result = query.list();

tx.commit();

return result != null && !result.isEmpty() ? result.get(0) : null;

}

POM文件:

<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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.paul.licenta</groupId>
<artifactId>teachApp</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>teachApp</name>

<build>
<finalName>teachApp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>3.0.0.ga</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.3.0.GA</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0-m08</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.10.Final</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>22.0</version>
</dependency>


<!-- for JPA, use hibernate-entitymanager instead of hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.3.10.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.34</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-search-orm</artifactId>
<version>5.3.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0</version>
</dependency>
<!-- uncomment this to get JSON support
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
-->
</dependencies>
<properties>
<jersey.version>2.26-b03</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

这是我得到的错误:

SEVERE: StandardWrapper.Throwable
java.lang.NoClassDefFoundError: javax/ws/rs/client/RxInvokerProvider
at org.glassfish.jersey.internal.inject.Providers.getJaxRsProviderInterfaces(Providers.java:114)
at org.glassfish.jersey.internal.inject.Providers.<clinit>(Providers.java:87)
at org.glassfish.jersey.model.internal.ComponentBag.modelFor(ComponentBag.java:435)
at org.glassfish.jersey.model.internal.ComponentBag.lambda$registerModel$5(ComponentBag.java:394)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.model.internal.ComponentBag.registerModel(ComponentBag.java:386)
at org.glassfish.jersey.model.internal.ComponentBag.register(ComponentBag.java:297)
at org.glassfish.jersey.model.internal.CommonConfig.register(CommonConfig.java:459)
at org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:447)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:332)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1269)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1182)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1072)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5368)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5660)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.client.RxInvokerProvider
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
... 27 more

Aug 06, 2017 11:27:45 AM org.apache.catalina.core.StandardContext loadOnStartup
SEVERE: Servlet [Jersey Web Application] in web application [/teachApp] threw load() exception
java.lang.ClassNotFoundException: javax.ws.rs.client.RxInvokerProvider
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1892)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1735)
at org.glassfish.jersey.internal.inject.Providers.getJaxRsProviderInterfaces(Providers.java:114)
at org.glassfish.jersey.internal.inject.Providers.<clinit>(Providers.java:87)
at org.glassfish.jersey.model.internal.ComponentBag.modelFor(ComponentBag.java:435)
at org.glassfish.jersey.model.internal.ComponentBag.lambda$registerModel$5(ComponentBag.java:394)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
at org.glassfish.jersey.model.internal.ComponentBag.registerModel(ComponentBag.java:386)
at org.glassfish.jersey.model.internal.ComponentBag.register(ComponentBag.java:297)
at org.glassfish.jersey.model.internal.CommonConfig.register(CommonConfig.java:459)
at org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:447)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:332)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1269)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1182)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1072)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5368)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5660)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1571)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1561)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

Aug 06, 2017 11:27:45 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Aug 06, 2017 11:27:45 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Aug 06, 2017 11:27:45 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 9144 ms
java.lang.NoSuchMethodError: org.hibernate.SessionFactory.openSession()Lorg/hibernate/Session;

我尝试添加在互联网上建议的其他 jar 以及我在这里找到的其他一些东西,但到目前为止没有任何效果。我希望它在身份验证后将我重定向到指定的页面。有什么想法吗?

非常感谢!

最佳答案

我实际上遇到了同样的问题..我的解决方案基于以下内容:

  • RxInvokerProvider 在 2.1 版的 jaxrs-api 中 -> 你引用的是 2.0

  • jersey 2.26依赖jaxrs 2.1

在此问题之后,您将面临“注入(inject)”问题(https://github.com/jersey/jersey/blob/12e5d8bdf22bcd2676a1032ed69473cf2bbc48c7/docs/src/main/docbook/migration.xml),因此您将需要 jersey-hk 依赖项

 <dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${jersey.version}</version>
</dependency>

关于hibernate - java.lang.ClassNotFoundException : javax. ws.rs.client.RxInvokerProvider 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45530132/

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