Building Spring 2 Enterprise Applications phần 3

thông báo rằng mùa xuân vẫn hoàn toàn tương thích ngược với Spring . Hơn nữa, Spring làm việc với Java và xa hơn nữa và với J2EE và xa hơn nữa. Điều này có nghĩa là bạn có thể thả mùa xuân JAR trong các dự án hiện tại của bạn, và bạn sẽ không có một sự phụ thuộc duy nhất bị hỏng. | 56 CHAPTER 2 THE CORE CONTAINER Implementing Factory Objects We ve already discussed the advantage of factory objects compared to factory methods they allow for an extra layer of configuration. Bean definitions that call a method on a factory object use two attributes the factory-bean attribute which refers to the factory object and the factory-method which indicates the method to call on the factory object. Listing 2-42 demonstrates configuring the class as a factory object. Listing 2-42. Configuring SimpleDateFormat As a Factory Object in the Container xml version encoding UTF-8 DOCTYPE beans PUBLIC - SPRING DTD BEAN EN http dtd beans -- 1 -- bean id socketFactory class factory-method getDefault bean bean id localhost factory-bean socketFactory factory-method createSocket constructor-arg value localhost constructor-arg value 80 bean bean id factory-bean socketFactory factory-method createSocket constructor-arg value constructor-arg value 80 bean beans In Listing 2-42 we first configure the class using the factory-method attribute which creates beans from a static factory method in this case getDefault . Next we use the socketFactory bean as a factory object in the two subsequent bean definitions where we call the createSocket method and provide it with two arguments. The configuration in Listing 2-42 is typical for factory objects where one bean definition configures the factory object and one or more other bean definitions call methods on the factory object. In fact this method of object construction is not just for factories. It provides a generic mechanism for object construction. Listing 2-43 shows the integration test for this factory object configuration. Listing 2-43. Obtaining the Sockets Created Using the Factory Cbject package import import .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
80    388    2    05-07-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.