gpt4 book ai didi

java - JSF/Hibernate/Rest,为什么是空指针?

转载 作者:行者123 更新时间:2023-12-02 06:23:50 26 4
gpt4 key购买 nike

我尝试基于JSF和hibernate做一个休息服务。数据库在 Jbossstandalone.xml 中指定。但是应该给我 MediaType.APPLICATION_JSON 的 Url 却给了我一个 Nullpointer 。de.bht.server/rest/resource/json

package de.bht.server.jax;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import com.database.Service;
import com.database.SurveyQuestion;

@Path("/resource")
public class Resource {

@Inject
private Service service;

// This method is called if Json request
@GET
@Path("/json")
@Produces(MediaType.APPLICATION_JSON)
public List<SurveyQuestion> getJson() {
System.out.println("Resource: " + service);
return service.getAllQuestions();
}

@GET
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public List<SurveyQuestion> getTestJson() {

ArrayList<SurveyQuestion> list = new ArrayList<SurveyQuestion>();
SurveyQuestion sq = new SurveyQuestion();

sq.setFreetext(true);
sq.setId(5l);
sq.setIdx(6);
sq.setMandatory(true);
sq.setMultiplechoice(true);
sq.setSheet_id(7l);
sq.setTitle("What's app?");

for (int i = 0; i < 3; ++i)
list.add(sq);

return list;
}
}

我的休息应用程序

package de.bht.server.jax;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/rest")
public class RestApplication extends Application {

}

我的注入(inject)服务

package com.database;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

@Stateless
public class Service {

@PersistenceContext
private EntityManager em;

public List<SurveyQuestion> getAllQuestions() {
System.out.println("Service: " + em);
final Query query = this.em.createNamedQuery("getWholeTable");

System.out.println("ServicePrint: " + query);

return query.getResultList();
}

}

还有我尝试绘制的 Pojo

package com.database;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
@Entity
@NamedQuery(name = "getWholeTable", query = "select t from SurveyQuestion t")
@Table(name = "survey_question", schema = "tnt_test")
public class SurveyQuestion implements Serializable {

/**
*
*/
private static final long serialVersionUID = 4571690522451469184L;

@Id
@GeneratedValue
@Column(name = "id")
private Long id;

@Column(name = "freetext")
private boolean freetext;

@Column(name = "idx")
private Integer idx;

@Column(name = "mandatory")
private boolean mandatory;

@Column(name = "multiplechoice")
private boolean multiplechoice;

@Column(name = "title")
private String title;

@Column(name = "sheet_id")
private Long sheet_id;

public SurveyQuestion() {

}

public boolean getFreetext() {
return freetext;
}

public void setFreetext(boolean freetext) {
this.freetext = freetext;
}

public Integer getIdx() {
return idx;
}

public void setIdx(Integer idx) {
this.idx = idx;
}

public boolean getMandatory() {
return mandatory;
}

public void setMandatory(boolean mandatory) {
this.mandatory = mandatory;
}

public boolean getMultiplechoice() {
return multiplechoice;
}

public void setMultiplechoice(boolean multiplechoice) {
this.multiplechoice = multiplechoice;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public Long getSheet_id() {
return sheet_id;
}

public void setSheet_id(Long sheet_id) {
this.sheet_id = sheet_id;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

@Override
public String toString() {
return "SurveyQuestion ,id=" + id + ", freetext=" + freetext + ", idx="
+ idx + ", mandatory=" + mandatory + ", multiplechoice="
+ multiplechoice + ", title=" + title + ", sheet_id="
+ sheet_id;
}

}

我的堆栈跟踪

2013-12-25 13:12:53,075 INFO  [org.jboss.modules]  JBoss Modules version 1.1.3.GA
2013-12-25 13:12:53,310 INFO [org.jboss.msc] JBoss MSC version 1.0.2.GA
2013-12-25 13:12:53,388 INFO [org.jboss.as] JBAS015899: JBoss AS 7.2.0.Alpha1-SNAPSHOT "Steropes" starting
2013-12-25 13:12:54,496 INFO [org.jboss.as.server.deployment.scanner] JBAS015003: Found de.bht.server.war in deployment directory. To trigger deployment create a file called de.bht.server.war.dodeploy
2013-12-25 13:12:54,528 INFO [org.xnio] XNIO Version 3.0.6.GA
2013-12-25 13:12:54,528 INFO [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)
2013-12-25 13:12:54,528 INFO [org.xnio.nio] XNIO NIO Implementation Version 3.0.6.GA
2013-12-25 13:12:54,544 INFO [org.jboss.remoting] JBoss Remoting version 3.2.8.SP1
2013-12-25 13:12:54,590 INFO [org.jboss.as.configadmin] JBAS016200: Activating ConfigAdmin Subsystem
2013-12-25 13:12:54,606 INFO [org.jboss.as.osgi] JBAS011906: Activating OSGi Subsystem
2013-12-25 13:12:54,606 INFO [org.jboss.as.naming] JBAS011800: Activating Naming Subsystem
2013-12-25 13:12:54,622 INFO [org.jboss.as.security] JBAS013171: Activating Security Subsystem
2013-12-25 13:12:54,668 INFO [org.jboss.as.security] JBAS013170: Current PicketBox version=4.0.13.Final
2013-12-25 13:12:54,746 INFO [org.jboss.as.webservices] JBAS015537: Activating WebServices Extension
2013-12-25 13:12:54,746 INFO [org.jboss.as.connector.logging] JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.12.Final)
2013-12-25 13:12:54,793 INFO [org.jboss.as.naming] JBAS011802: Starting Naming Service
2013-12-25 13:12:54,809 INFO [org.jboss.as.mail.extension] JBAS015400: Bound mail session [java:jboss/mail/Default]
2013-12-25 13:12:54,980 INFO [org.jboss.as.connector.subsystems.datasources] JBAS010404: Deploying non-JDBC-compliant driver class org.postgresql.Driver (version 9.2)
2013-12-25 13:12:55,043 INFO [org.jboss.ws.common.management.AbstractServerConfig] JBoss Web Services - Stack CXF Server 4.1.0.Beta2
2013-12-25 13:12:55,074 INFO [org.jboss.as.connector.subsystems.datasources] JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)
2013-12-25 13:12:55,526 INFO [org.jboss.as.server.deployment.scanner] JBAS015012: Started FileSystemDeploymentService for directory C:\Development\jboss_as\standalone\deployments
2013-12-25 13:12:55,526 INFO [org.jboss.as.server.deployment] JBAS015876: Starting deployment of "de.bht.server.war"
2013-12-25 13:12:55,950 INFO [org.jboss.as.remoting] JBAS017100: Listening on 127.0.0.1:10004
2013-12-25 13:12:55,950 INFO [org.jboss.as.remoting] JBAS017100: Listening on 127.0.0.1:4452
2013-12-25 13:12:55,950 INFO [org.apache.coyote.http11.Http11Protocol] Starting Coyote HTTP/1.1 on http-localhost/127.0.0.1:8085
2013-12-25 13:12:56,090 INFO [org.jboss.as.connector.subsystems.datasources] JBAS010400: Bound data source [java:jboss/datasources/WebappFrameworkDS]
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.javac.handlers.HandleConstructor$HandleAllArgsConstructor' for service type 'lombok.javac.JavacAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.javac.handlers.HandleConstructor$HandleNoArgsConstructor' for service type 'lombok.javac.JavacAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.javac.handlers.HandleConstructor$HandleRequiredArgsConstructor' for service type 'lombok.javac.JavacAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.javac.handlers.HandleLog$HandleCommonsLog' for service type 'lombok.javac.JavacAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.javac.handlers.HandleLog$HandleJulLog' for service type 'lombok.javac.JavacAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.javac.handlers.HandleLog$HandleLog4j2Log' for service type 'lombok.javac.JavacAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.javac.handlers.HandleLog$HandleLog4jLog' for service type 'lombok.javac.JavacAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.javac.handlers.HandleLog$HandleSlf4jLog' for service type 'lombok.javac.JavacAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.javac.handlers.HandleLog$HandleXSlf4jLog' for service type 'lombok.javac.JavacAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.core.Main$LicenseApp' for service type 'lombok.core.LombokApp'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.core.Main$VersionApp' for service type 'lombok.core.LombokApp'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.installer.Installer$CommandLineInstallerApp' for service type 'lombok.core.LombokApp'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.installer.Installer$CommandLineUninstallerApp' for service type 'lombok.core.LombokApp'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.installer.Installer$GraphicalInstallerApp' for service type 'lombok.core.LombokApp'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.eclipse.handlers.HandleConstructor$HandleAllArgsConstructor' for service type 'lombok.eclipse.EclipseAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.eclipse.handlers.HandleConstructor$HandleNoArgsConstructor' for service type 'lombok.eclipse.EclipseAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.eclipse.handlers.HandleConstructor$HandleRequiredArgsConstructor' for service type 'lombok.eclipse.EclipseAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.eclipse.handlers.HandleLog$HandleCommonsLog' for service type 'lombok.eclipse.EclipseAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.eclipse.handlers.HandleLog$HandleJulLog' for service type 'lombok.eclipse.EclipseAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.eclipse.handlers.HandleLog$HandleLog4j2Log' for service type 'lombok.eclipse.EclipseAnnotationHandler'
2013-12-25 13:12:58,665 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.eclipse.handlers.HandleLog$HandleLog4jLog' for service type 'lombok.eclipse.EclipseAnnotationHandler'
2013-12-25 13:12:58,681 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.eclipse.handlers.HandleLog$HandleSlf4jLog' for service type 'lombok.eclipse.EclipseAnnotationHandler'
2013-12-25 13:12:58,681 WARN [org.jboss.as.server.deployment] JBAS015893: Encountered invalid class name 'lombok.eclipse.handlers.HandleLog$HandleXSlf4jLog' for service type 'lombok.eclipse.EclipseAnnotationHandler'
2013-12-25 13:12:58,962 INFO [org.jboss.as.jpa] JBAS011401: Read persistence.xml for database
2013-12-25 13:12:59,368 INFO [org.jboss.weld.deployer] JBAS016002: Processing weld deployment de.bht.server.war
2013-12-25 13:12:59,992 INFO [org.jboss.weld.deployer] JBAS016005: Starting Services for CDI deployment: de.bht.server.war
2013-12-25 13:13:00,102 INFO [org.jboss.weld.Version] WELD-000900 1.1.16 (Final)
2013-12-25 13:13:00,165 INFO [org.jboss.as.jpa] JBAS011402: Starting Persistence Unit Service 'de.bht.server.war#database'
2013-12-25 13:13:00,321 INFO [org.hibernate.annotations.common.Version] HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
2013-12-25 13:13:00,321 INFO [org.hibernate.Version] HHH000412: Hibernate Core {4.1.6.Final}
2013-12-25 13:13:00,336 INFO [org.hibernate.cfg.Environment] HHH000206: hibernate.properties not found
2013-12-25 13:13:00,336 INFO [org.hibernate.cfg.Environment] HHH000021: Bytecode provider name : javassist
2013-12-25 13:13:00,352 INFO [org.hibernate.ejb.Ejb3Configuration] HHH000204: Processing PersistenceUnitInfo [
name: database
...]
2013-12-25 13:13:00,586 INFO [org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator] HHH000130: Instantiating explicit connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
2013-12-25 13:13:01,273 INFO [org.hibernate.dialect.Dialect] HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2013-12-25 13:13:01,273 INFO [org.hibernate.engine.jdbc.internal.LobCreatorBuilder] HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
2013-12-25 13:13:01,289 INFO [org.hibernate.engine.transaction.internal.TransactionFactoryInitiator] HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jta.CMTTransactionFactory
2013-12-25 13:13:01,289 INFO [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] HHH000397: Using ASTQueryTranslatorFactory
2013-12-25 13:13:01,321 INFO [org.hibernate.cache.spi.UpdateTimestampsCache] HHH000250: Starting update timestamps cache at region: de.bht.server.war#database.org.hibernate.cache.spi.UpdateTimestampsCache
2013-12-25 13:13:01,321 INFO [org.infinispan.factories.GlobalComponentRegistry] ISPN000128: Infinispan version: Infinispan 'Brahma' 5.1.7.Final
2013-12-25 13:13:01,461 INFO [org.infinispan.jmx.CacheJmxRegistration] ISPN000031: MBeans were successfully registered to the platform mbean server.
2013-12-25 13:13:01,477 INFO [org.hibernate.cache.internal.StandardQueryCache] HHH000248: Starting query cache at region: de.bht.server.war#database.org.hibernate.cache.internal.StandardQueryCache
2013-12-25 13:13:01,477 INFO [org.infinispan.jmx.CacheJmxRegistration] ISPN000031: MBeans were successfully registered to the platform mbean server.
2013-12-25 13:13:01,493 INFO [org.hibernate.validator.util.Version] Hibernate Validator 4.2.0.Final
2013-12-25 13:13:01,728 INFO [org.infinispan.jmx.CacheJmxRegistration] ISPN000031: MBeans were successfully registered to the platform mbean server.
2013-12-25 13:13:01,868 INFO [org.hibernate.tool.hbm2ddl.SchemaValidator] HHH000229: Running schema validator
2013-12-25 13:13:01,868 INFO [org.hibernate.tool.hbm2ddl.SchemaValidator] HHH000102: Fetching database metadata
2013-12-25 13:13:01,899 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] HHH000261: Table found: tnt_test.survey_question
2013-12-25 13:13:01,899 INFO [org.hibernate.tool.hbm2ddl.TableMetadata] HHH000037: Columns: [id, title, multiplechoice, idx, mandatory, sheet_id, freetext]
2013-12-25 13:13:02,040 INFO [org.jboss.weld.deployer] JBAS016008: Starting weld service for deployment de.bht.server.war
2013-12-25 13:13:02,274 INFO [org.apache.deltaspike.core.util.ClassDeactivationUtils] class: org.apache.deltaspike.core.impl.config.ConfigurationExtension activated=true
2013-12-25 13:13:02,274 INFO [org.apache.deltaspike.core.util.ClassDeactivationUtils] class: org.apache.deltaspike.core.impl.exception.control.extension.ExceptionControlExtension activated=true
2013-12-25 13:13:02,274 INFO [org.apache.deltaspike.core.util.ClassDeactivationUtils] class: org.apache.deltaspike.security.impl.extension.SecurityExtension activated=true
2013-12-25 13:13:02,289 INFO [org.apache.deltaspike.core.util.ClassDeactivationUtils] class: org.apache.deltaspike.core.impl.message.MessageBundleExtension activated=true
2013-12-25 13:13:02,289 INFO [org.apache.deltaspike.core.util.ClassDeactivationUtils] class: org.apache.deltaspike.core.impl.exclude.extension.ExcludeExtension activated=true
2013-12-25 13:13:02,289 INFO [org.apache.deltaspike.core.util.ClassDeactivationUtils] class: org.apache.deltaspike.core.impl.exclude.CustomProjectStageBeanFilter activated=true
2013-12-25 13:13:02,289 INFO [org.apache.deltaspike.core.util.ClassDeactivationUtils] class: org.apache.deltaspike.core.impl.exclude.GlobalAlternative activated=true
2013-12-25 13:13:02,289 INFO [org.apache.deltaspike.core.util.ClassDeactivationUtils] class: org.apache.deltaspike.core.impl.jmx.MBeanExtension activated=true
2013-12-25 13:13:02,368 INFO [org.apache.deltaspike.core.util.ProjectStageProducer] Computed the following DeltaSpike ProjectStage: Production
2013-12-25 13:13:03,554 INFO [org.jboss.web] JBAS018210: Register web context: /de.bht.server
2013-12-25 13:13:03,726 INFO [javax.enterprise.resource.webcontainer.jsf.config] Mojarra 2.1.13-jbossorg-1 20120919-1641 für Kontext '/de.bht.server' wird initialisiert.
2013-12-25 13:13:07,127 INFO [org.primefaces.webapp.PostConstructApplicationEventListener] Running on PrimeFaces 4.0
2013-12-25 13:13:08,002 INFO [org.jboss.as.server] JBAS018559: Deployed "de.bht.server.war"
2013-12-25 13:13:08,205 INFO [org.jboss.as] JBAS015961: Http management interface listening on http://127.0.0.1:9995/management
2013-12-25 13:13:08,205 INFO [org.jboss.as] JBAS015951: Admin console listening on http://127.0.0.1:9995
2013-12-25 13:13:08,205 INFO [org.jboss.as] JBAS015874: JBoss AS 7.2.0.Alpha1-SNAPSHOT "Steropes" started in 15582ms - Started 204 of 288 services (83 services are passive or on-demand)
2013-12-25 13:13:15,567 INFO [org.jboss.resteasy.cdi.CdiInjectorFactory] Found BeanManager at java:comp/BeanManager
2013-12-25 13:13:15,567 INFO [org.jboss.resteasy.spi.ResteasyDeployment] Deploying javax.ws.rs.core.Application: class de.bht.server.jax.RestApplication
2013-12-25 13:13:15,693 INFO [stdout] Resource: null

2013-12-25 13:13:15,709 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/de.bht.server].[de.bht.server.jax.RestApplication]] Servlet.service() for servlet de.bht.server.jax.RestApplication threw exception: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:340)
at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214)
at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190)
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:540)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:502)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:206)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:179)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50)
at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:165)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:372)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at de.bht.server.jax.Resource.getJson(Resource.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:167)
at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:525)
... 28 more

好像是

 @Inject
private Service service;

资源中存在一些问题,但这是为什么呢?我很感谢任何提示。

最佳答案

您的问题的简短答案是,放置一个名为 beans.xml 的空文件。进入 WEB-INF 文件夹。

或者,您可以使用 @EJB 来注释您的服务。

请参阅此答案以获得更长的解释:Should I use @EJB or @Inject

关于java - JSF/Hibernate/Rest,为什么是空指针?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20772810/

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