On object injection by spring5 framework

CSDN Q & A 2022-06-24 06:56:57 阅读数:110

objectinjectionspring5springframework
The phenomenon and background of the problem
Operation results and error reporting contents
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <bean id="service1" class="com.atguigu.spring5.Service.UserService"><property name="userDao" ref="dao" ></property> </bean> <bean id="dao" class="com.atguigu.spring5.Dao.UserDaoImpl"></bean></beans>

spring Framework of the bean Object , this xml Is there anything wrong with the document ? Why can't I find it name by service1 Of bean

img

My solution ideas and tried methods
What I want to achieve

This is the test code

package com.atguigu.spring5.Test;import com.atguigu.spring5.Service.UserService;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;public class UserServiceTest { public static void main(String[] args) { ApplicationContext context=new ClassPathXmlApplicationContext("service.xml"); UserService service = context.getBean("service1", UserService.class); service.add(); }}



Take the answer :

Yours service Let's go class Is it an interface , To put service The implementation class of


copyright:author[CSDN Q & A],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/175/202202150002035336.html