我一直在尝试使用自动装配,但它无法自动装配。这是代码片段,
应用上下文文件:
<context:annotation-config />
<context:component-scan base-package="com.shapes" />
<bean id = "triangle" class = "com.shapes.Triangle" autowire="byName"></bean>
三角班:
@Component
public class Triangle implements Shape {
@Override
public void draw() {
System.out.println("In draw");
}
}
主要课程:
public class MainShapes {
@Autowired
private Triangle triangle;
/**
* @param args
*/
public static void main(String[] args) {
MainShapes shapes = new MainShapes();
shapes.triangle.draw();
}
}