gpt4 book ai didi

java - 在 JBoss 7.1 上运行 Rest 项目时出错

转载 作者:行者123 更新时间:2023-11-30 07:12:32 25 4
gpt4 key购买 nike

我在 JBoss 7.1 上创建了一个 REST 项目。我给你所需的类(class):

User.java

@XmlRootElement(name = "user")
public class User implements Serializable {
private static final long serialVersionUID = 1L;
private int id;
private String name;
private String profession;

public User(){}

public User(int id, String name, String profession){
this.id = id;
this.name = name;
this.profession = profession;
}

public int getId() {
return id;
}
@XmlElement
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
@XmlElement
public void setName(String name) {
this.name = name;
}
public String getProfession() {
return profession;
}
@XmlElement
public void setProfession(String profession) {
this.profession = profession;
}
}

ListBean.java

@ManagedBean
@ViewScoped
public class ListBean {
private static Client client;
private static String REST_SERVICE_URL = "http://localhost:8080/UserManagement/rest/UserService/users";
private static final String SUCCESS_RESULT="<result>success</result>";
private static final String PASS = "pass";
private static final String FAIL = "fail";
private List<User> users;
private transient DataModel<User> model;
private User user;
private int id;
private String name;
private String profession;

private void init(){
this.client = ClientBuilder.newClient();
}

@PostConstruct
public void initialize()
{
ListBean tester = new ListBean();
tester.init();
GenericType<List<User>> list = new GenericType<List<User>>() {};
users = client.target(REST_SERVICE_URL)
.request(MediaType.APPLICATION_XML)
.get(list);
String result = PASS;
if(users.isEmpty()){
result = FAIL;
}
List<User> lus = new ArrayList<User>();
for(User u : users){
lus.add(u);
}
user = new User();
}
}

UserService.java

@Path("/UserService")
public class UserService
{
UserDao userDao = new UserDao();
private static final String SUCCESS_RESULT="<result>success</result>";
private static final String FAILURE_RESULT="<result>failure</result>";

@GET
@Path("/users")
@Produces(MediaType.APPLICATION_XML)
public List<User> getUsers(){
return userDao.getAllUsers();
}
}

运行后出现如下异常:

20:49:39,045 INFO  [org.jboss.as.server] (Controller Boot Thread) JBAS018559: Deployed "sqljdbc4.jar"
20:49:39,050 INFO [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015876: Starting deployment of "UserManagement.war"
20:49:40,026 WARN [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015893: Encountered invalid class name 'com.sun.faces.vendor.Tomcat6InjectionProvider:org.apache.catalina.util.DefaultAnnotationProcessor' for service type 'com.sun.faces.spi.injectionprovider'
20:49:40,028 WARN [org.jboss.as.server.deployment] (MSC service thread 1-2) JBAS015893: Encountered invalid class name 'com.sun.faces.vendor.Jetty6InjectionProvider:org.mortbay.jetty.plus.annotation.InjectionCollection' for service type 'com.sun.faces.spi.injectionprovider'
20:49:40,241 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC00001: Failed to start service jboss.deployment.unit."UserManagement.war".POST_MODULE: org.jboss.msc.service.StartException in service jboss.deployment.unit."UserManagement.war".POST_MODULE: Failed to process phase POST_MODULE of deployment "UserManagement.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [rt.jar:1.7.0_55]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.7.0_55]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.7.0_55]
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: JBAS011232: Only one JAX-RS Application Class allowed. org.glassfish.jersey.server.ResourceConfig$WrappingResourceConfig org.glassfish.jersey.server.ResourceConfig$RuntimeConfig org.glassfish.jersey.server.ResourceConfig
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.scan(JaxrsScanningProcessor.java:209)
at org.jboss.as.jaxrs.deployment.JaxrsScanningProcessor.deploy(JaxrsScanningProcessor.java:105)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more

该项目在 Tomcat6 和 7 上运行良好,但 JBoss 7.1 存在问题。

最佳答案

所以相关的异常是这样的:

JBAS011232: Only one JAX-RS Application Class allowed

感谢:

然后,我遇到了这个问题:

java.lang.NoSuchMethodError: javax.ws.rs.core.MultivaluedMap.addAll(Ljava/lang/Object;[Ljava/lang/Object;)V

解决方法:

  • 我创建了一些类实现了可序列化
  • 我在 META-INF 下添加了文件 jboss-deployment-struction.xml:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<deployment>
<exclusions>
<!-- Exclude RestEasy conflict -->
<module name="javaee.api" />
<module name="javax.ws.rs.api"/>
<module name="org.jboss.resteasy.resteasy-jaxrs" />
</exclusions>
</deployment>
</jboss-deployment-structure>

结果,我的项目也运行良好。

关于java - 在 JBoss 7.1 上运行 Rest 项目时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38983697/

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