Introduction to the basics of Spring

  1. Create Dynamic Webproject project
  2. Import the relevant coordinates (jar package) (spring-context, tomcat server, and
  3. Create an ApplicationContext.xml file under the sc directory (the header file that can be imported can be found on the Internet
  4. Create a dao package under the sc directory, create the interface TestDao (plus the method sayHello()) below, and use TestDaoimpl for the implementation class (inherit the method sayHello() in the TestDao package).
  5. Add
    < in the ApplicationContext.xml filebean id="test" class="com.dao.TestDaoimpl"> <bean>
  6. Create an implementation class Test.java under the sc directory and call the getBean() method
  7. Add to the implementation class
package com.demo.controller;


import com.demo.dao.impl.TestDaoimpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestController {
    
    
    public static void main(String[] args) {
    
    

    ApplicationContext app= new ClassPathXmlApplicationContext("ApplicationContext.xml");
        TestDaoimpl testDaoimpl= (TestDaoimpl) app.getBean( "test" );
        testDaoimpl.sayHello();

    }
}

Note: If an error is reported, it may be that the jar has not been imported, and the jar package needs to be imported again

Guess you like

Origin blog.csdn.net/houzhicongone/article/details/114526662