1

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 property and WARNING: Setting property 'source' to 'org.eclipse.jst.jee.server:appname' did not find a matching property

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).

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.

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

<?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:

<?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:

<?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

<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):

@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. -> /SpitterWebMaven in local

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.

Community
  • 1
  • 1
SerhatCan
  • 590
  • 1
  • 7
  • 26
  • It happens if the resource is not available. Can you post your Controller file and also let us know the url that you are trying to invoke – Zeus Jul 14 '14 at 23:04
  • I added my controller which is very basic HelloWorldController and my url which is localhost:8080/SpitterWebMaven – SerhatCan Jul 15 '14 at 06:02
  • Same thing happened to me, just trying to get the http://www.tutorialspoint.com/spring/spring_mvc_hello_world_example.htm tutorial to work. Took an embarrassingly long time staring at 404s to discover what @SerhatCan figured out, that in the "Setting property 'source' to 'org.eclipse.jst.j2ee.server:' " warning, the app is now accessible form localhost:8080//hello. Will post back later if I figure anything out but I need to burn off some steam. – jjr4826 May 01 '16 at 22:40

1 Answers1

0

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.

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
jjr4826
  • 194
  • 3
  • 12