404 spring tomcat mapping?

In my spring project, I have:

HTTP Status 404 -

--------------------------------------------------------------------------------

type Status report

message

description The requested resource () is not available.

The web.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

  <servlet>
    <servlet-name>home</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
      <param-name>contextClass</param-name>
      <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
    </init-param>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>main.java.com.codetutr.springconfig</param-value>
    </init-param>
  
  </servlet>
  
  <servlet-mapping>
    <servlet-name>home</servlet-name>
    <url-pattern>/home.jsp</url-pattern>
  </servlet-mapping>

  <welcome-file-list>
  	<welcome-file>/home.jsp</welcome-file>
  </welcome-file-list>
</web-app>

Open in new window


Webconfig.java:
package com.codetutr.springconfig;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages="com.codetutr")
public class WebConfig extends WebMvcConfigurerAdapter {

	/**
	 * Since we don't have any controller logic, simpler to just
	 * define controller for page using View Controller. Note:
	 * had to extend WebMvcConfigurerAdapter to get this functionality
	 * @param registry
	 */
	@Override
	public void addViewControllers(ViewControllerRegistry registry) {
		registry.addViewController("/").setViewName("home");
	}
	
	@Bean
	public InternalResourceViewResolver viewResolver() {
		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
		resolver.setPrefix("/WEB-INF/view/");
		resolver.setSuffix(".jsp");
		return resolver;
	}
	
}

Open in new window


But tomcat cannot locate the file, it seems so i suspect the problem is due to url pattern.

Regards.
LVL 12
jazzIIIloveAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>main.java.com.codetutr.springconfig</param-value>
    </init-param>
The <param-value> should be the a package to start scanning from. I guess you are also using maven, and that's why you are thinking this, but you don't need the "main.java." part on the front of that. That's not part of the package name. Try this instead...
     <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>com.codetutr.springconfig</param-value>
    </init-param>

Open in new window

0
jazzIIIloveAuthor Commented:
hi;

this is the complete code i am using (at the end of the page):
http://codetutr.com/2013/03/24/simple-spring-mvc-web-application-using-gradle/

I still couldn't solve this.

regards.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Did you still get the same error after making the change I said?

What is the URL that you are trying to access, that is not working?
0
jazzIIIloveAuthor Commented:
Hi;

I couldn't make the change as I wasn't sure. I am just trying to run
http://codetutr.com/2013/03/24/simple-spring-mvc-web-application-using-gradle/

Regards.
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
I couldn't make the change as I wasn't sure
What is not to be sure about? In the code that you posted above for your web.xml file, you have...
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>main.java.com.codetutr.springconfig</param-value>
    </init-param>

Open in new window

You need to change the <param-value> line (line 3) of that snippet so that it looks like this...
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>com.codetutr.springconfig</param-value>
    </init-param>

Open in new window

Notice the I have removed main.java. from the start of <param-value>


I am just trying to run
http://codetutr.com/2013/03/24/simple-spring-mvc-web-application-using-gradle/
And that website has the correct param-value line in web.xml that I am giving you here, so you must have changed it yourself.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.