Java 将属性 'source' 设置为 'org.eclipse.jst.jee.server(404 错误)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24746825/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 14:40:04  来源:igfitidea点击:

Setting property 'source' to 'org.eclipse.jst.jee.server (404 Error)

javaspringmavenspring-mvc

提问by SerhatCan

I have a Simple Spring Web Maven project. I'm getting 404 error. I already looked at the following post: Setting property 'source' to 'org.eclipse.jst.jee.server:JSFTut' did not find a matching propertyand WARNING: Setting property 'source' to 'org.eclipse.jst.jee.server:appname' did not find a matching property

我有一个简单的 Spring Web Maven 项目。我收到 404 错误。我已经看过以下帖子:将属性“源”设置为“org.eclipse.jst.jee.server:JSFTut”没有找到匹配的属性警告:将属性“源”设置为“org.eclipse.jst.jee” .server:appname' 没有找到匹配的属性

Both of them saying that this is not an error and you can ignore it. They also say you need to specify your localhost:8080/(aplication-context).

他们俩都说这不是错误,您可以忽略它。他们还说您需要指定您的localhost:8080/(aplication-context).

But I can not get rid of the 404 error and can't get any page. I have tried also creating a web project without maven. Still can't figure it out. Please help me get through this.

但是我无法摆脱 404 错误并且无法获取任何页面。我也尝试过在没有 maven 的情况下创建一个 web 项目。还是想不通。请帮我解决这个问题。

Here is my log:

这是我的日志:

Tem 15, 2014 12:58:57 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jdk1.7.0_60\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Broadcom\Broadcom 802.11\Driver;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\SSH Communications Security\SSH Secure Shell;.
Tem 15, 2014 12:58:57 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
Tem 15, 2014 12:58:57 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Tem 15, 2014 12:58:57 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 429 ms
Tem 15, 2014 12:58:57 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Tem 15, 2014 12:58:57 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.54
Tem 15, 2014 12:58:57 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor C:\Users\Serhat Can\workspace-spring\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost\SpitterWebMaven.xml
Tem 15, 2014 12:58:57 AM org.apache.catalina.startup.SetContextPropertiesRule begin
WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:SpitterWebMaven' did not find a matching property.
Tem 15, 2014 12:58:58 AM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deployment of configuration descriptor C:\Users\Serhat Can\workspace-spring\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost\SpitterWebMaven.xml has finished in 85 ms
Tem 15, 2014 12:58:58 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
Tem 15, 2014 12:58:58 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Tem 15, 2014 12:58:58 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 486 ms

My web.xml file

我的 web.xml 文件

<?xml version="1.0" encoding="ISO-8859-1"?>
<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_2_5.xsd"
         id="WebApp_ID" version="2.5">

    <display-name>SpitterWebMaven</display-name>

   <!--
        - Location of the XML file that defines the root application context.
        - Applied by ContextLoaderListener.
    -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring/application-config.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <!--
        - Servlet that dispatches request to registered handlers (Controller implementations).
    -->
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/mvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

My mvc-config.xml file:

我的 mvc-config.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- Uncomment and your base-package here: -->
         <context:component-scan
            base-package="com.spitter.webs.controller"/> 


    <mvc:annotation-driven />

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!-- Example: a logical view name of 'showMessage' is mapped to '/WEB-INF/jsp/showMessage.jsp' -->
            <property name="prefix" value="/WEB-INF/view/"/>
            <property name="suffix" value=".jsp"/>
    </bean>

</beans>

My application-config.xml file:

我的 application-config.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

    <!-- Root Context: defines shared resources visible to all other web components -->

    <!-- Uncomment and add your base-package here: -->
    <context:component-scan base-package="com.spitter.web" />


     <bean id="emf"
             class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
             <property name="dataSource" ref="dataSource" />
             <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
             <property name="packagesToScan" value="com.spitter.web.domain"></property>
       </bean>




    <!-- data source to connect mysql db -->
    <bean name="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/spring_jpa" />
        <property name="username" value="root" />
        <property name="password" value="root" />
    </bean>



    <bean id="jpaVendorAdapter"
        class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
        <property name="database" value="MYSQL" />
        <property name="showSql" value="true" />
        <property name="generateDdl" value="false" />
        <property name="databasePlatform" value="org.hibernate.dialect.MySQL5Dialect" />
    </bean>







    <!-- why do we need this! -->
    <bean
        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

    <!-- why do we need this! -->
    <bean
        class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

    <!-- why do we need this! -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="emf" />
    </bean>


    <tx:annotation-driven transaction-manager="transactionManager" />


</beans>

Finally my pom.xml

最后我的 pom.xml

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.springframework.samples.service.service</groupId>
  <artifactId>SpitterWebMaven</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

    <properties>

        <!-- Generic properties -->
        <java.version>1.6</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>


             <!-- Web -->

             <jsp.version>2.2</jsp.version>

             <jstl.version>1.2</jstl.version>

             <servlet.version>2.5</servlet.version>





             <!-- Spring -->

             <spring-framework.version>3.2.3.RELEASE</spring-framework.version>



             <!-- Hibernate / JPA -->

             <hibernate.version>4.2.1.Final</hibernate.version>



             <!-- Logging -->

             <logback.version>1.0.13</logback.version>

             <slf4j.version>1.7.5</slf4j.version>



             <!-- Test -->

             <junit.version>4.11</junit.version>



       </properties>



       <dependencies>



             <!-- Spring MVC -->

             <dependency>

                    <groupId>org.springframework</groupId>

                    <artifactId>spring-webmvc</artifactId>

                    <version>${spring-framework.version}</version>

             </dependency>

             <dependency>

                    <groupId>org.springframework</groupId>

                    <artifactId>spring-context</artifactId>

                    <version>${spring-framework.version}</version>

             </dependency>

             <dependency>

                    <groupId>org.springframework</groupId>

                    <artifactId>spring-jdbc</artifactId>

                    <version>${spring-framework.version}</version>

             </dependency>

             <dependency>

                    <groupId>org.springframework</groupId>

                    <artifactId>spring-context-support</artifactId>

                    <version>${spring-framework.version}</version>

             </dependency>

             <dependency>

                    <groupId>org.springframework</groupId>

                    <artifactId>spring-orm</artifactId>

                    <version>${spring-framework.version}</version>

             </dependency>

             <dependency>

                    <groupId>javax.inject</groupId>

                    <artifactId>javax.inject</artifactId>

                    <version>1</version>

             </dependency>

             <!-- Other Web dependencies -->

             <dependency>

                    <groupId>javax.servlet</groupId>

                    <artifactId>jstl</artifactId>

                    <version>${jstl.version}</version>

             </dependency>

             <dependency>

                    <groupId>javax.servlet</groupId>

                    <artifactId>servlet-api</artifactId>

                    <version>${servlet.version}</version>

                    <scope>provided</scope>

             </dependency>

             <dependency>

                    <groupId>javax.servlet.jsp</groupId>

                    <artifactId>jsp-api</artifactId>

                    <version>${jsp.version}</version>

                    <scope>provided</scope>

             </dependency>



             <!-- Spring and Transactions -->

             <dependency>

                    <groupId>org.springframework</groupId>

                    <artifactId>spring-tx</artifactId>

                    <version>${spring-framework.version}</version>

             </dependency>

             <!-- AspectJ -->

             <dependency>

                    <groupId>org.aspectj</groupId>

                    <artifactId>aspectjlib</artifactId>

                    <version>1.6.2</version>

             </dependency>

             <dependency>

                    <groupId>org.aspectj</groupId>

                    <artifactId>aspectjweaver</artifactId>

                    <version>1.8.1</version>

             </dependency>

             <!-- Logging with SLF4J & LogBack -->

             <dependency>

                    <groupId>org.slf4j</groupId>

                    <artifactId>slf4j-api</artifactId>

                    <version>${slf4j.version}</version>

                    <scope>compile</scope>

             </dependency>

             <dependency>

                    <groupId>ch.qos.logback</groupId>

                    <artifactId>logback-classic</artifactId>

                    <version>${logback.version}</version>

                    <scope>runtime</scope>

             </dependency>

             <!-- H2 -->

             <!-- <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId>

                    <version>1.4.179</version> </dependency> -->

             <!-- MySql -->

             <dependency>

                    <groupId>mysql</groupId>

                    <artifactId>mysql-connector-java</artifactId>

                    <version>5.1.31</version>

             </dependency>

             <!-- Hibernate -->

             <dependency>

                    <groupId>org.hibernate</groupId>

                    <artifactId>hibernate-entitymanager</artifactId>

                    <version>${hibernate.version}</version>

             </dependency>

             <!-- Apache Commons -->

             <dependency>

                    <groupId>org.apache.commons</groupId>

                    <artifactId>commons-lang3</artifactId>

                    <version>3.3.2</version>

             </dependency>

             <dependency>

                    <groupId>org.apache.commons</groupId>

                    <artifactId>commons-dbcp2</artifactId>

                    <version>2.0.1</version>

             </dependency>





             <!-- Test Artifacts -->

             <dependency>

                    <groupId>org.springframework</groupId>

                    <artifactId>spring-test</artifactId>

                    <version>${spring-framework.version}</version>

                    <scope>test</scope>

             </dependency>

             <dependency>

                    <groupId>junit</groupId>

                    <artifactId>junit</artifactId>

                    <version>${junit.version}</version>

                    <scope>test</scope>

             </dependency>

             <dependency>

                    <groupId>org.mockito</groupId>

                    <artifactId>mockito-all</artifactId>

                    <version>1.9.5</version>

             </dependency>





             <dependency>

                    <groupId>javax.validation</groupId>

                    <artifactId>validation-api</artifactId>

                    <version>1.1.0.Final</version>

             </dependency>

       </dependencies>

</project>

--UPDATE--

- 更新 -

My hello controller (I try to use very basic controller to see if it works. Also, I have hello.jsp in WEB-INF->view):

我的 hello 控制器(我尝试使用非常基本的控制器来查看它是否有效。另外,我在 WEB-INF->view 中有 hello.jsp):

@Controller
public class HelloWorldController {

    @RequestMapping("/hello")
    public ModelAndView helloWorld() {

        String message = "Hello World, Spring 3.0!";
        return new ModelAndView("hello", "message", message);
    }
}

I have tried lost of url's but here is the default URL that comes when I run the server. -> /SpitterWebMavenin local

我试过丢失 url,但这是我运行服务器时出现的默认 URL。->/SpitterWebMaven在本地

Another think that I want to add is when I first created the project run on server button was not displaying and I chose Java and Dynamic Web Project to see the run on server button after a research on how to do that.

我想补充的另一个想法是,当我第一次创建项目时,在服务器上运行按钮没有显示,我选择了 Java 和动态 Web 项目来查看在服务器上运行按钮后如何执行此操作。

回答by jjr4826

Not an answer to why or how this is happening, but there is a connection between (project properties --> Web Project Settings --> Context Root) and the root url of the dispatchServlet.

不是为什么或如何发生这种情况的答案,但是(项目属性 --> Web 项目设置 --> 上下文根)和 dispatchServlet 的根 url 之间存在联系。

Try:

尝试:

  1. Changing Context Root to other than root url currently available (SpitterWebMaven), which should also be the Servers --> Tomcat ... --> server.xml Server.Service.Engine.Host.Context.path value
  2. clean the server and restart
  3. You should now be able to access via the base url also the server.xml Server.Service.Engine.Host.Context.path value should be changed to
  1. 将 Context Root 更改为当前可用的 root url 以外的 (SpitterWebMaven),这也应该是 Servers --> Tomcat ... --> server.xml Server.Service.Engine.Host.Context.path 值
  2. 清理服务器并重新启动
  3. 您现在应该能够通过基本 url 访问 server.xml Server.Service.Engine.Host.Context.path 值也应该更改为