gpt4 book ai didi

java - 通过 TomEE plus 服务器连接到 POJO?

转载 作者:行者123 更新时间:2023-11-28 22:02:30 32 4
gpt4 key购买 nike

我在 Eclipse Kepler EE 中创建了一个动态 Web 项目,将其连接到 Tomee plus 1.7.1 服务器并创建了一个 servlet 和一个 POJO。因此,在打开浏览器并尝试对类执行某些操作后,servlet 按预期工作,但 POJO 返回错误 404。

实际代码是这样的:

//小服务程序

public class MyServlet extends HttpServlet {  
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("I'm a servlet.");
}
}

//web.xml

<servlet>  
<servlet-name>MyServlet</servlet-name>
<servlet-class>package.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/MyServlet</url-pattern>
</servlet-mapping>

因此,当我输入“localhost:8080//MyServlet”时,我得到了预期的“我是一个 servlet”。信息。问题出在 POJO 上:

//POJO

@Path("/MyPOJO")  
public class MyPOJO {
@GET
public String get() throws IOExeption {
return "I'm a POJO.";
}
}

我对 web.xml 文件中的那个类一无所知。我有这个类(class),但我真的不知道它是做什么的:

 @ApplicationPath("/sth")  
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>(Arrays.asList(MyPOJO.class));
}
}

Application是M2_REPO\javax\ws\rs\javax.ws.rs-api\2.0.1\javax.ws.rs-api-2.0.1.jar中的一个类

所以当我输入“localhost:8080//sth/MyPOJO”时,我得到错误 404,没有异常没有日志。我试过调试,但没有遇到任何断点。

可能和我启动服务器时出现的异常有关:

Nov 19, 2014 6:44:50 PM org.apache.myfaces.ee6.MyFacesContainerInitializer onStartup 
INFO: Added FacesServlet with mappings=[/faces/*, *.jsf, *.faces]
Nov 19, 2014 6:44:51 PM org.apache.myfaces.config.DefaultFacesConfigurationProvider getStandardFacesConfig
INFO: Reading standard config META-INF/standard-faces-config.xml
Nov 19, 2014 6:44:51 PM org.apache.myfaces.webapp.AbstractFacesInitializer initFaces
SEVERE: An error occured while initializing MyFaces: WebAppBuilder not found in SystemInstance. Ensure the following entry exists in the Tomcat server.xml file: <Listener className="org.apache.tomee.catalina.ServerListener"/>
java.lang.IllegalStateException: WebAppBuilder not found in SystemInstance. Ensure the following entry exists in the Tomcat server.xml file: <Listener className="org.apache.tomee.catalina.ServerListener"/>
at org.apache.tomee.myfaces.TomEEAnnotationProvider.getAnnotatedClasses(TomEEAnnotationProvider.java:43)
at org.apache.myfaces.config.annotation.AnnotationConfigurator.createFacesConfig(AnnotationConfigurator.java:90)
at org.apache.myfaces.config.DefaultFacesConfigurationProvider.getAnnotationsFacesConfig(DefaultFacesConfigurationProvider.java:152)
at org.apache.myfaces.config.DefaultFacesConfigurationMerger.getFacesConfigData(DefaultFacesConfigurationMerger.java:91)
at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:416)
at org.apache.myfaces.webapp.AbstractFacesInitializer.buildConfiguration(AbstractFacesInitializer.java:370)
at org.apache.myfaces.webapp.Jsp21FacesInitializer.initContainerIntegration(Jsp21FacesInitializer.java:73)
at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:143)
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:119)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4937)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
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)

Nov 19, 2014 6:44:51 PM org.apache.catalina.util.SessionIdGenerator createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [162] milliseconds.
Nov 19, 2014 6:44:59 PM org.apache.myfaces.ee6.MyFacesContainerInitializer onStartup
INFO: Added FacesServlet with mappings=[/faces/*, *.jsf, *.faces]
Nov 19, 2014 6:44:59 PM org.apache.myfaces.config.DefaultFacesConfigurationProvider getStandardFacesConfig
INFO: Reading standard config META-INF/standard-faces-config.xml
Nov 19, 2014 6:44:59 PM org.apache.myfaces.webapp.AbstractFacesInitializer initFaces
SEVERE: An error occured while initializing MyFaces: WebAppBuilder not found in SystemInstance. Ensure the following entry exists in the Tomcat server.xml file: <Listener className="org.apache.tomee.catalina.ServerListener"/>
java.lang.IllegalStateException: WebAppBuilder not found in SystemInstance. Ensure the following entry exists in the Tomcat server.xml file: <Listener className="org.apache.tomee.catalina.ServerListener"/>
at org.apache.tomee.myfaces.TomEEAnnotationProvider.getAnnotatedClasses(TomEEAnnotationProvider.java:43)
at org.apache.myfaces.config.annotation.AnnotationConfigurator.createFacesConfig(AnnotationConfigurator.java:90)
at org.apache.myfaces.config.DefaultFacesConfigurationProvider.getAnnotationsFacesConfig(DefaultFacesConfigurationProvider.java:152)
at org.apache.myfaces.config.DefaultFacesConfigurationMerger.getFacesConfigData(DefaultFacesConfigurationMerger.java:91)
at org.apache.myfaces.config.FacesConfigurator.configure(FacesConfigurator.java:416)
at org.apache.myfaces.webapp.AbstractFacesInitializer.buildConfiguration(AbstractFacesInitializer.java:370)
at org.apache.myfaces.webapp.Jsp21FacesInitializer.initContainerIntegration(Jsp21FacesInitializer.java:73)
at org.apache.myfaces.webapp.AbstractFacesInitializer.initFaces(AbstractFacesInitializer.java:143)
at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:119)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4937)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
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)

我已尝试添加 server.xml 文件中缺少的行,但服务器根本无法启动。

当我的大学试图在他的 PC 上运行它时,它可以与 POJO 和 Servlet 一起工作。我们找不到它不在我的电脑上运行的任何原因。

最佳答案

终于成功了。我不得不重新下载 TomEE+。也许我的版本有误。

关于java - 通过 TomEE plus 服务器连接到 POJO?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27034676/

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