Results 1 to 2 of 2
  1. #1
    frenk_castle is offline Member
    Join Date
    Mar 2010
    Location
    Belgrade, Serbia
    Posts
    27
    Rep Power
    0

    Default ResourceBundleViewResolver properties file

    Hi

    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. I created a class

    Java 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

    Java 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 a views.properties file

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

    Java 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)
    It seems that ResourceBundleViewResolver is not finding or loading views.properties file. I copied this file to every folder within my springpractice folder but it didn't help.

    Could somebody please offer me some advice?

    Thanks in advance

  2. #2
    rshekher is offline Member
    Join Date
    Apr 2011
    Posts
    2
    Rep Power
    0

    Default Products-index

    I thinks the problem shud arised either in Model or in view.properties .
    A small Sugesstion .. Please take off "-" and rename to Productsindex.

    And try .

    Let me know .

    Regards,
    Raj

Similar Threads

  1. Accessing Properties File
    By java_men in forum Java Servlet
    Replies: 0
    Last Post: 05-11-2010, 11:34 AM
  2. Reading a properties file
    By peiceonly in forum New To Java
    Replies: 7
    Last Post: 05-06-2010, 05:17 PM
  3. Unable to access velocity.properties file from jar file
    By mjwoodford in forum New To Java
    Replies: 0
    Last Post: 10-09-2009, 01:46 PM
  4. Not able to load a properties file
    By Happy9959 in forum New To Java
    Replies: 12
    Last Post: 07-29-2008, 07:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •