简体   繁体   English

Eclipse在运行tomcat时未检测到任何错误,但找不到bean

[英]Eclipse detects no errors but can't find bean when running tomcat

Eclipse does not detect any errors in the code but when I run it through tomcat, it won't render in the browser because it cannot locate the resource. Eclipse不会在代码中检测到任何错误,但是当我通过tomcat运行它时,它将无法在浏览器中呈现,因为它无法找到资源。 The console says 控制台说

Unable to load configuration. - bean - jar:file:/Users/jasonrodriguez/Java/apache-tomcat-7.0.47/wtpwebapps/TutorialFinder/WEB-INF/lib/struts2-gxp-plugin-2.3.15.3.jar!/struts-plugin.xml:8:162 

but my library path is connected to lib like it is supposed to and I have the whole library of jars. 但是我的库路径像应该的那样连接到lib ,并且我拥有整个jars库。 Am I missing something? 我想念什么吗?

Here is my action class : 这是我的动作课:

package org.koushik.javabrains.action;

import org.koushik.javabrains.service.TutorialFinderService;

public class TutorialAction {
    public String execute() {
        TutorialFinderService tutorialFinderService = new TutorialFinderService();
        String bestTutorialSite = tutorialFinderService.getBestTutorialSite();
        System.out.println(bestTutorialSite);
        return "success";
    }

}

struts.xml : struts.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <package name="default" namespace="/tutorials" extends="struts-default">
        <action name="getTutorial" class="org.koushik.javabrains.action.TutorialAction">
            <result name="success">/success.jsp</result>
            <result name="failure">/error.jsp</result>
        </action>
    </package>
</struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>TutorialFinder</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>

      <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      </filter>

      <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
</web-app>

Here is a screenshot of my file hierarchy : 这是我的文件层次结构的屏幕截图:

在此处输入图片说明

Here are my jars : 这是我的罐子:

在此处输入图片说明在此处输入图片说明在此处输入图片说明在此处输入图片说明

Your dependencies are used only at compile time. 您的依赖项仅在编译时使用。 To include library (like struts) you must configure "Deployment Assembly" in project's properties. 要包括库(如struts),必须在项目的属性中配置“ Deployment Assembly”。 Here you can find a description of the feature. 您可以在此处找到有关功能的说明。

It seems you have created a Eclipse library that point to the lib folder of the Struts2 distro and added it to classpath (or build path whatever they call it). 看来您已经创建了一个指向Struts2发行版的lib文件夹的Eclipse库,并将其添加到classpath(或构建路径,无论他们如何称呼)。

It's not bad if you want your project to be compiled, it has to resolve dependencies to the configured libraries. 如果要编译项目,这还不错,它必须解决对已配置库的依赖关系。 But the problem is along with compile time dependencies you have added a runtime dependencies that are all deployed to the application server when you run your application. 但是问题在于编译时依赖性,您添加了运行时依赖性,这些依赖性在运行应用程序时全部部署到应用程序服务器。 It's not good. 这不好。

As far as I remember a newer versions of Eclipse has something called "web deployment assembly" and it's described here . 据我所知,Eclipse的较新版本具有称为“ Web部署程序集”的内容, 在此进行了描述。 Combined with maven you can get better control applying scopes to this feature. 与maven结合使用,您可以更好地控制将范围应用于此功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM