Good morning,
I try to create my first web site using Spring 3. But there is problem how to set common properties to run simple web application.
I use Eclipse 3.4.1, Tomcat 6.0, Java version 1.6.
In a web folder of Tomcat, there is a folder webapps, which is set to be WorkSpace for Eclipse. I've made new Java Project named "Spring3". Project Spring3 includes folder WEB-INF, which includes "lib" folder, "classes" folder and Spring3-servlet.xml and web.xml.
lib
I added all jar from dist folder and commons-logging and "Builded path" adding these jar.
web.xml
Spring3-servlet.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>Spring 3</display-name> <servlet> <servlet-name>Spring3</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Spring3</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.htm</welcome-file> </welcome-file-list> </web-app>
"Classes" folder contents 2 classes: Spring3.java and Spring3Test.javaCode:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="Spring3Bean" class="classes.Spring3" /> </beans>
Spring3.java
Spring3Test.javaCode:package classes; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class Spring3 { @RequestMapping("/hello.htm") public void sayHola() { System.out.println("Hola spring 3.0!"); } }
Code:package classes; import org.springframework.beans.factory.xml.XmlBeanFactory; import org.springframework.core.io.ClassPathResource; public class Spring3Test { public static void main(String[] args) { XmlBeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource( "Spring3-servlet.xml")); Spring3 simpleSpringBean = (Spring3) beanFactory.getBean("Spring3Bean"); simpleSpringBean.sayHola(); } }
I've run my code as Java application in the Eclipse.
Problem is, that my Web browser returns this error message: Cannot find class [classes.Spring3] for bean with name 'Spring3Bean' defined in ServletContext resource [/WEB-INF/Spring3-servlet.xml];


Reply With Quote
