user3016535
user3016535

Reputation: 15

spring-Unnamed bean definition specifies neither 'class' nor 'parent' nor 'factory-bean' - can't generate bean name

I met a problem below

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unnamed bean definition specifies neither 'class' nor 'parent' nor 'factory-bean' - can't generate bean name
Offending resource: ServletContext resource [/WEB-INF/sample-servlet.xml]

sample-servlet.xml code ,i don't know how to fix it

<?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:p="http://www.springframework.org/schema/p"
    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">

    <context:component-scan base-package="com.spring.controller"/>

    <bean p:viewClass="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/pages/"
          p:suffix=".jsp"/>

</beans>

is there someone who can help me? Thanks a lot!

Upvotes: 1

Views: 5908

Answers (1)

Sotirios Delimanolis
Sotirios Delimanolis

Reputation: 279960

Your bean definition

<bean p:viewClass="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/pages/"
      p:suffix=".jsp"/>

doesn't declare a class attribute which is mandatory in this case. It should be

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:viewClass="some view class"
      p:prefix="/WEB-INF/pages/"
      p:suffix=".jsp"/>

The p:viewClass attribute is referring to the property named viewClass in the InternalResourceViewResolver class. Obviously, set an appropriate value, maybe org.springframework.web.servlet.view.JstlView or org.springframework.web.servlet.view.InternalResourceView.

This and more are explained in the official documentation.

Upvotes: 2

Related Questions