Spring Bean Definition Inheritance | Spring Boot
springbean
2
inheritance
1
springboot
138
Male avatar

loveprogramming viết ngày 28/04/2021

https://grokonez.com/spring-framework/spring-bean-definition-inheritance-spring-boot

Spring Bean Definition Inheritance | Spring Boot

Bean Definition Inheritance is a good solution for defining new bean which inherited certain bean conveniently.

We will learn how to use XML configuration to create Inheritance from Bean with parent or abstract template.

I. Demo Video

II. Technology

  • Java 1.8
  • Maven 3.3.9
  • Spring Tool Suite – Version 3.8.1.RELEASE
  • Spring Boot: 1.4.0.RELEASE

    III. Overview

    1. Goal

    beandefinheritance-goal To build an application that runs with beans:
  • customerService is bean parent of:
  • anotherCustomerService: bean without declaring new class (use the same class as customerService)
  • telephoneService: bean of new class, inherit property from customerService and add new property too.
  • beanWelcomeTemplate: a parent bean as abstract template that child beans can inherit.
  • consultationService: child bean of beanWelcomeTemplate

    2. Project Structure

    beandefinheritance-projectstructure

    3. Step to do

  • Create Spring Boot project
  • Create Services
  • Create Spring Bean Configuration File
  • Create a Web Controller
  • Run Spring Boot Application & Enjoy Result

    IV. Practice

    1. Create Spring Boot project

  • Open Spring Tool Suite, on Menu, choose File -> New -> Spring Starter Project, then fill each field: beandefinheritance-projectstart

Click Next, in Web: choose Web:
springaop-aspectj-configweb

Click Finish. Spring Boot project will be created successfully.

2. Create Services

Under package service, create class CustomerService and SpecificService</strong.

Content of CustomerService.java:


public class CustomerService {
    private String welcomeMessage;
    private String customerName;

    public String getWelcomeMessage() {
        return welcomeMessage;
    }

    public void setWelcomeMessage(String welcomeMessage) {
        this.welcomeMessage = welcomeMessage;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public String sayHello() {
        return welcomeMessage + " " + customerName;
    }
}

Content of SpecificService.java:

More at:

https://grokonez.com/spring-framework/spring-bean-definition-inheritance-spring-boot

Spring Bean Definition Inheritance | Spring Boot

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

Male avatar

loveprogramming

451 bài viết.
79 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
Male avatar
1 0
Tutorial Link: (Link) (Ảnh) Django is a Pythonbased free and opensource web framework that follows the modeltemplateview architectural pattern. A...
loveprogramming viết 6 tháng trước
1 0
Male avatar
1 0
https://loizenai.com/angular11nodejspostgresqlcrudexample/ Angular 11 Node.js PostgreSQL Crud Example (Ảnh) Tutorial: “Angular 11 Node.js Postg...
loveprogramming viết 5 tháng trước
1 0
Male avatar
1 0
Angular Spring Boot jwt Authentication Example Github https://loizenai.com/angularspringbootjwt/ (Ảnh) Tutorial: ” Angular Spring Boot jwt Authe...
loveprogramming viết 5 tháng trước
1 0
Bài viết liên quan
Male avatar
0 0
https://grokonez.com/springframework/springbeanscopessingletonprototype Spring Bean Scopes – Singleton and Prototype Spring Bean Scopes helps yo...
loveprogramming viết 16 ngày trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


Male avatar
{{userFollowed ? 'Following' : 'Follow'}}
451 bài viết.
79 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!