Я пытался внести много изменений в классе драйверов или AppConfig, но все же не получает его.
Код: Выделить всё
@Component
public class Point {
@Value("10")
int x;
@Value("20")
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
@Override
public String toString() {
return "Point [x=" + x + ", y=" + y + "]";
}
}
< /code>
line.class
@Component
public class Line implements Shape {
private int size;
private String type;
@Autowired
Point pointA;
@Autowired
Point pointB;
public Line() {
}
public Line(int size, String type, Point pointA, Point pointB) {
super();
this.size = size;
this.type = type;
this.pointA = pointA;
this.pointB = pointB;
}
@Override
public String toString() {
return "Triangle [size=" + size + ", type=" + type + ", pointA=" + pointA + ", pointB=" + pointB + "]";
}
/*
getters and setters.....
*/
}
< /code>
applicationconfig.class
@ComponentScan
@Configuration
public class ApplicationConfig {
@Bean
public Line line() { return new Line(); }
@Bean
public Point point() { return new Point(); }
}
< /code>
drawingApp.class
public class DrawingApp {
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext(ApplicationConfig.class);
Shape line = context.getBean(Line.class);
System.out.println(line);
}
< /code>
Мой вывод всегда такой, хотя я установил значения x & y как 10 и 20 соответственно: < /p>
Line [size=0, type=null, pointA=Point [x=0, y=0], pointB=Point [x=0, y=0]]
Подробнее здесь: https://stackoverflow.com/questions/675 ... set-values