Announcement Announcement Module
Collapse
No announcement yet.
ResourceBundleViewResolver problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ResourceBundleViewResolver problem

    Hi

    If the question is in the wrong section please move it to the appropriate one.

    I have been learning Spring from book Pro Spring 2.5 for some time now. I have a problem with one of the examples from the book which I deploy on Tomcat 7.0.4. I created a class

    Code:
    package practice;
    
    import java.util.ArrayList;
    import java.util.Date;
    import java.util.List;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
    
    public class ProductController extends MultiActionController{
    	
    	private List<Product> products;
    	
    	private Product createProduct(Long productId, String name, Date expirationDate) {
    		Product product = new Product();
    		product.setId(productId);
    		product.setName(name);
    		product.setExpirationDate(expirationDate);
    		return product;
    	}
    	
    	public ProductController() {
    		products = new ArrayList<Product>();
    		Date today = new Date();
    		products.add(createProduct(1L, "test", today));
    		products.add(createProduct(2L, "Pro Spring Appes", today));
    		products.add(createProduct(3L, "Pro Velocity", today));
    		products.add(createProduct(4L, "Pro VS.NET", today));
    	}
    	
    	public ModelAndView indexHandler(HttpServletRequest request, HttpServletResponse response) {
    		return new ModelAndView("products-index", "products", products);
    	}
    }
    application context file

    Code:
    <?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"
    	xsi:schemaLocation="
    		http://www.springframework.org/schema/beans
    		http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    		http://www.springframework.org/schema/context
    		http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    
    	<bean id="PublicUrlMapping"
    			class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    		<property name="mappings">
    			<value>
    				/index.html=indexController
    				/product/index.html=productController
    			</value>
    		</property>
    	</bean>
    	<bean id="viewResolver"
    			class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
    		<property name="basename" value="views"/>
    	</bean>
    	<bean id="internalPathMethodNameResolver"
              class="org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver">
            <property name="suffix" value="Handler"/>
        </bean>
    	<bean id="indexController"
    			class="practice.IndexController">
    	</bean>
    	<bean id="productController"
              class="practice.ProductController">
            <property name="methodNameResolver" ref="internalPathMethodNameResolver"/>
        </bean>
    </beans>
    and views.properties file

    Code:
    #index
    products-index.class=org.springframework.web.servlet.view.JstlView
    products-index.url=/WEB-INF/views/product/index.jsp
    When I go to url http://localhost:8080/springpractice/product/index.html

    indexHandler method of ProductController class gets invoked properly but I receive this error:

    Code:
    type Exception report
    
    message
    
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception
    
    org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'products-index': Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    
    root cause
    
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'products-index': Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    	org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    	org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    	org.springframework.web.servlet.view.ResourceBundleViewResolver.initFactory(ResourceBundleViewResolver.java:251)
    	org.springframework.web.servlet.view.ResourceBundleViewResolver.loadView(ResourceBundleViewResolver.java:194)
    	org.springframework.web.servlet.view.AbstractCachingViewResolver.createView(AbstractCachingViewResolver.java:158)
    	org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName(AbstractCachingViewResolver.java:77)
    	org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1078)
    	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1027)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    
    root cause
    
    java.lang.IllegalStateException: No bean class specified on bean definition
    	org.springframework.beans.factory.support.AbstractBeanDefinition.getBeanClass(AbstractBeanDefinition.java:372)
    	org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:52)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    	org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    	org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    	org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    	org.springframework.web.servlet.view.ResourceBundleViewResolver.initFactory(ResourceBundleViewResolver.java:251)
    	org.springframework.web.servlet.view.ResourceBundleViewResolver.loadView(ResourceBundleViewResolver.java:194)
    	org.springframework.web.servlet.view.AbstractCachingViewResolver.createView(AbstractCachingViewResolver.java:158)
    	org.springframework.web.servlet.view.AbstractCachingViewResolver.resolveViewName(AbstractCachingViewResolver.java:77)
    	org.springframework.web.servlet.DispatcherServlet.resolveViewName(DispatcherServlet.java:1078)
    	org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1027)
    	org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:817)
    	org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
    	org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
    	org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    	javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    I placed the views.properties file in /Tomcat/webapps/springpractice/WEB-INF/classes directory and it seems ResourceBundleViewResolver is finding it. But I still get this error and I can't figure out why or how to solve it.

    Could somebody please offer me some advice?

    Thanks in advance

  • #2
    Well I suggest a read of the reference guide (or follow the sample which you try to follow).

    .class isn't a property it should .(class)..

    Comment


    • #3
      Thank you very much. I copied the views.properties context directly from the book. They wrote there with out the brackets.

      Thank for the reference guide also I will learn a lot from there.

      Comment

      Working...
      X