Browse Source

2024年4月8日 22点21分

Starlight-0208 5 tháng trước cách đây
mục cha
commit
fdaab98bc0

+ 3 - 7
src/main/java/org/starter/learning/AppTest.java

@@ -11,12 +11,8 @@ import org.starter.learning.test.TestBaseImpl2;
 
 public class AppTest {
     public static void main(String[] args) {
-//        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
-        ApplicationContext ctx = new FileSystemXmlApplicationContext("D:\\Java Project\\learning\\src\\main\\resources\\applicationContext.xml");
-//        TestBase testBase = (TestBase) ctx.getBean("testBase");
-//        TestBase testBase = ctx.getBean("testBase", TestBase.class);
-        TestBase testBase = ctx.getBean(TestBase.class);
-        testBase.output();
-        System.out.println(System.getenv().get("USERNAME"));
+        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
+//        TestBase testBase = ctx.getBean(TestBase.class);
+//        testBase.output();
     }
 }

+ 3 - 3
src/main/java/org/starter/learning/AppTestForBeanFactory.java

@@ -9,9 +9,9 @@ import org.starter.learning.test.TestBase;
 
 public class AppTestForBeanFactory {
     public static void main(String[] args) {
-        Resource resource = new ClassPathResource("application.xml");
+        Resource resource = new ClassPathResource("applicationContext.xml");
         BeanFactory bf = new XmlBeanFactory(resource);
-        TestBase testBase = bf.getBean(TestBase.class);
-        testBase.output();
+//        TestBase testBase = bf.getBean(TestBase.class);
+//        testBase.output();
     }
 }

+ 4 - 0
src/main/java/org/starter/learning/test/TestBaseImpl.java

@@ -3,6 +3,10 @@ package org.starter.learning.test;
 import java.util.*;
 
 public class TestBaseImpl implements TestBase {
+    public TestBaseImpl() {
+        System.out.println("Constructor called.");
+    }
+
     private int[] array;
     private List<String> list;
     private Set<String> set;

+ 43 - 4
src/main/resources/applicationContext.xml

@@ -10,9 +10,48 @@
 <!--            <property name="username" value="${jdbc.username}" />-->
 <!--            <property name="password" value="${jdbc.password}" />-->
 <!--        </bean>-->
-    <bean id="testBase" class="org.starter.learning.test.TestBaseImpl2">
-        <property name="username" value="${username}" />
-        <property name="password" value="${jdbc.password}" />
-    </bean>
+<!--    <bean id="testBaseOld" class="org.starter.learning.test.TestBaseImpl2">-->
+<!--        <property name="username" value="${jdbc.username}" />-->
+<!--        <property name="password" value="${jdbc.password}" />-->
+<!--    </bean>-->
 
+    <bean id="testBase" class="org.starter.learning.test.TestBaseImpl" >
+        <property name="array">
+            <array>
+                <value>100</value>
+                <value>200</value>
+                <value>300</value>
+            </array>
+        </property>
+        <property name="list">
+            <list>
+                <value>string1</value>
+                <value>string2</value>
+                <value>string3</value>
+            </list>
+        </property>
+        <property name="set">
+            <set>
+                <value>value1</value>
+                <value>value2</value>
+                <value>value2</value>
+                <value>value3</value>
+            </set>
+        </property>
+        <property name="map">
+            <map>
+                <entry key="country" value="China" />
+                <entry key="province" value="Shanxi" />
+                <entry key="city" value="Datong" />
+            </map>
+        </property>
+        <property name="properties">
+            <props>
+                <prop key="country" >China</prop>
+                <prop key="province">ShanXi</prop>
+                <prop key="city">Datong</prop>
+            </props>
+        </property>
+    </bean>
+    <bean id="bookDao" class="org.starter.learning.dao.impl.BookDaoImpl" lazy-init="true" />
     </beans>