在写beanAnnotation时的问题

来源:4-1 Spring Bean装配之Bean的定义及作用域的注解实现

青柳立夏

2018-05-12 20:22

<?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.xsd

        http://www.springframework.org/schema/context

        http://www.springframework.org/schema/context/spring-context.xsd" >

        

        <context:component-scan base-package="main.java.beanAnnotation"></context:component-scan>

        

 </beans>


package main.java.beanAnnotation;


import org.springframework.stereotype.Component;



@Component

public class BeanAnnotation {

public void say(String word){

System.out.println("Annotation"+word+this.hashCode());

}

}


import test.ioc.base.UnitTestBase;


public class TestBeanAnnotation extends UnitTestBase{

public TestBeanAnnotation(){

super("classpath:Spring-beanscope.xml");

}

@Test

public void testAnnotation(){

BeanAnnotation test=super.getBean("beanAnnotation");

test.say("第一个bean啊");

}


}



代码如上,报错:Unexpected exception parsing XML document from class path resource [Spring-beanscope.xml]; 


求解答

写回答 关注

2回答

  • 慕移动9181930
    2022-03-24 15:46:36

    lt;a?href="javascript:void(0);"gt;lt;/agt;这样也可以。#可以用于完成top的回到顶部操作,而void(0)是指空操作w3cp

  • 咕嘟咕嘟和布鲁鲁
    2018-05-13 09:35:07

    super.getBean("beanAnnotation")前要加强制类型转换,应该这样写:(BeanAnnotation)super.getBean("beanAnnotation")

Spring入门篇

为您带来IOC和AOP的基本概念及用法,为后续高级课程学习打下基础

268800 学习 · 1026 问题

查看课程

相似问题