diff --git a/out/production/Flowers-SpringProject-2205/bean-di-annotation.xml b/out/production/Flowers-SpringProject-2205/bean-di-annotation.xml new file mode 100644 index 0000000..be28a11 --- /dev/null +++ b/out/production/Flowers-SpringProject-2205/bean-di-annotation.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/out/production/Flowers-SpringProject-2205/com/ssm/di/annotation/Message.class b/out/production/Flowers-SpringProject-2205/com/ssm/di/annotation/Message.class new file mode 100644 index 0000000..1083e7f Binary files /dev/null and b/out/production/Flowers-SpringProject-2205/com/ssm/di/annotation/Message.class differ diff --git a/out/production/Flowers-SpringProject-2205/com/ssm/di/annotation/TestAnnotation.class b/out/production/Flowers-SpringProject-2205/com/ssm/di/annotation/TestAnnotation.class index 31616bf..eba659e 100644 Binary files a/out/production/Flowers-SpringProject-2205/com/ssm/di/annotation/TestAnnotation.class and b/out/production/Flowers-SpringProject-2205/com/ssm/di/annotation/TestAnnotation.class differ diff --git a/src/bean-di-annotation.xml b/src/bean-di-annotation.xml new file mode 100644 index 0000000..be28a11 --- /dev/null +++ b/src/bean-di-annotation.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/src/com/ssm/di/annotation/Message.java b/src/com/ssm/di/annotation/Message.java new file mode 100644 index 0000000..45b361a --- /dev/null +++ b/src/com/ssm/di/annotation/Message.java @@ -0,0 +1,62 @@ +package com.ssm.di.annotation; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component("message") + +public class Message { + @Value("123456") + private int id; + @Value("好看") + private String content; + @Value("张三") + private String author; + @Value("22") + private String age; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + + public String getAge() { + return age; + } + + public void setAge(String age) { + this.age = age; + } + + @Override + public String toString() { + return "Messsage{" + + "id=" + id + + ", content='" + content + '\'' + + ", author=" + author + '\'' + + ", age" + age + '\'' + + '}'; + } +} diff --git a/src/com/ssm/di/annotation/TestAnnotation.java b/src/com/ssm/di/annotation/TestAnnotation.java index 5526e92..764b63d 100644 --- a/src/com/ssm/di/annotation/TestAnnotation.java +++ b/src/com/ssm/di/annotation/TestAnnotation.java @@ -1,9 +1,17 @@ package com.ssm.di.annotation; +import com.ssm.di.annotation.Message; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + public class TestAnnotation { public static void main(String[] args) { + ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean-di-annotation.xml"); + + Message message=(Message) applicationContext.getBean("message"); + System.out.println(message.toString()); } }