简体   繁体   中英

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!

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM