Τι είναι η Άνοιξη AOP,en – Let’s explore

Spring AOP

Ανοιξιάτικος Κύκλος,,en,Μάθετε Άνοιξη AOP από το Παράδειγμα,,en,Βασικά AOP,,en,Στο συγκρότημα ανάπτυξη εφαρμογών σημερινής τα ακόλουθα σημεία είναι πάντα διατηρούνται ως χώρος εστίασης,,en,Εφαρμογή θα πρέπει να αναπτυχθεί ως συνδυασμός αρθρωτά εξαρτήματα,,en,Όλα τα στοιχεία θα πρέπει να συνδεθούν χαλαρά,,en,Εξαρτήματα πρέπει να είναι επαναχρησιμοποιήσιμα,,en,Το πλεονέκτημα αυτής της προσέγγισης είναι,,en,Εύκολη συντήρηση και τη βελτίωση της εφαρμογής,,en,Εξαρτήματα μπορεί να επαναχρησιμοποιηθεί σε υφιστάμενα ή νέα εφαρμογή,,en,Μειώνει το κόστος της συντήρησης και την ενίσχυση,,en,Τώρα για να αντιμετωπίσει αυτές τις ανησυχίες άνοιξη έχει αναπτύξει τις έννοιες όπως η ΔΟΕ και AOP,,en,Έχουμε ήδη συζητήσει ΔΟΕ έτσι και τώρα θα επικεντρωθεί στην AOP,,en,AOP στοχεύει τις λειτουργικότητες εφαρμογή,,en,όπως υλοτομία,,en,συναλλαγή κ.λπ.,,en,που χρησιμοποιούνται σε όλη την εφαρμογή σε διάφορους τομείς,,en,Χρησιμοποιώντας AOP αυτά,,en,εγκάρσια κοπή,,en – Learn Spring AOP by Example

AOP Basics

In today’s complex application development the following points are always kept as a focus area.

  • Application should be developed as a combination of modular components.
  • All the components should be loosely coupled.
  • Components should be reusable.

The advantage of this approach is

  • Easy maintenance and enhancement of the application.
  • Components can be reused in the existing or new application.
  • Reduces the cost of maintenance and enhancement.

Now to address these concerns spring has developed the concepts like IOC and AOP. We have already discussed IOC so now we will concentrate on AOP.

Spring AOP

AOP targets the application functionalities (like logging, transaction etc) which are used throughout the application in different areas. Using AOP these cross-cutting Οι λειτουργικότητες αναπτύχθηκε ως επαναχρησιμοποιήσιμη συνιστώσα και εγχέεται εντός του εφαρμογής όπου απαιτείται ποτέ,,en,Και πάλι η όλη ρύθμιση γίνεται με τη χρήση του αρχείου xml,,en,Η εφαρμογή των AOP,,en,Ακόλουθο διάγραμμα παρουσιάζει ένα σύστημα διαχείρισης ταξιδιών,,en,Κρατήσεις εισιτηρίων»,,en,Ξενοδοχείο Κράτηση»,,en,Ταξίδια Σχεδιασμού,,en,»Είναι διαφορετικές λειτουργίες,,en,Τώρα όλες αυτές οι λειτουργίες απαιτούν υπηρεσίες όπως η υλοτομία,,en,συναλλαγών και την ασφάλεια,,en,Έτσι, αυτά είναι σταυρό ανησυχίες κοπής που έρχονται σε όλες τις ενότητες,,en,Οι ανησυχίες αυτές αναπτύχθηκε με βάση την αρχή της ΠΟΠ,,en,Όλες οι κοινές ανησυχίες αναπτύχθηκε ως ένα plug-in,,en,έτσι ώστε να μπορεί να χρησιμοποιηθεί σε μελλοντικές ενότητες, καθώς και,,en,Απλά πρέπει να το ρυθμίσετε έτσι ώστε η υπηρεσία είναι διαθέσιμη σε νέες ενότητες σας,,en,Αυτή είναι η δύναμη της προσανατολισμένη πτυχή προγραμματισμού,,en,AOP,,en. And again the entire configuration is done using xml file.

Implementation of AOP

Following diagram shows a travel management system. ‘Ticket Booking’, ‘Hotel Booking’ and ‘Travel Planning’ are different functionalities. Now all of these functionalities require services like logging, transaction and security. So these are cross cutting concerns which come across all the modules. These concerns are developed based on the principle of AOP.

All the common concerns are developed as a plug-in, so it can be used in future modules as well. You just need to configure it so that the service is also available in your new modules. This is the power of aspect oriented programming (AOP).

AOP εφαρμόζεται επίσης σε εφαρμογές στο επίπεδο της επιχείρησης,,en,Σε εφαρμογή της επιχείρησης,,en,ξύλευση,,en,την ασφάλεια και πολλά άλλα χαρακτηριστικά είναι εκεί σταυρό ανησυχίες κοπής,,en,Έτσι, όλα αυτά αναπτύσσονται ως πτυχές και διαμορφώνεται στο αρχείο xml,,en,Το μεγαλύτερο πλεονέκτημα είναι χαλαρή σύζευξη,,en,Όπως όλες οι ανησυχίες είναι αυτοδιαχειριζόμενο και ανεξάρτητο,,en,ώστε να μπορείτε να αλλάξετε και να ενισχύσει τους σύμφωνα με την απαίτησή σας χωρίς να αγγίξετε τον κώδικα εφαρμογής,,en,Σύστημα Διαχείρισης Ταξίδια,,en,Τώρα θα περιγράψουμε την εφαρμογή AOP ​​δείχνοντας ένα παράδειγμα,,en,πρώτα θα ορίσουμε μια διεπαφή και την κατηγορία της εφαρμογής της,,en,Αυτό είναι μια απλή εφαρμογή να συγκρίνει δύο ακέραιες τιμές και επιστρέφει το αποτέλεσμα,,en,Η Java είναι ο ορισμός διεπαφή για να συγκρίνετε δύο ακέραιες τιμές,,en,πακέτο com.techalpine,,en,CompareInt δημόσια διεπαφή,,en,δημόσια String συγκρίνετε,,en,Η Java είναι η τάξη εφαρμογή,,en. In enterprise application, συναλλαγή, logging, security and many more features are there as cross cutting concerns. So all of these are developed as aspects and configured in xml file.

The biggest advantage is loose coupling. As all the concerns are self-managed and independent, so you can change and enhance them as per your requirement without touching the application code.







Travel Management System

Now we will describe the AOP implementation by showing an example.

To start with, first we will define an interface and its implementation class. This is a simple application to compare two integer values and return the result.

Java is the interface definition to compare two integer values

package com.techalpine;

public interface CompareInt{

public String compare(int a,int b);

}

Java is the implementation class. Συγκρίνει δύο ακέραιες τιμές και επιστρέφει το αποτέλεσμα,,en,δημόσια τάξη CompareIntImpl υλοποιεί CompareInt,,en,επιστρέψει a »είναι μεγαλύτερη από» b,,en,b είναι μεγαλύτερο από ένα,,en,Τώρα θα γράψουμε μια απλή συμβουλή για να κληθεί πριν από την κλήση ο συγκρίνετε,,en,Η συμβουλή θα συζητηθεί λεπτομερώς στα επόμενα κεφάλαια,,en,Τώρα μπορείτε να φανταστείτε συμβουλές ως έργο το οποίο θα συνδεθεί στην εφαρμογή μέσω της ρύθμισης XML,,en,Και αυτό θα πρέπει να κληθεί πριν η μέθοδος καλείται,,en,Αλλά εκεί δεν θα έχει καμία άμεση κωδικοποίηση στο εσωτερικό της τάξης εφαρμογή,,en,Θα πάρει μόνο πριν από συμβουλές για την κατηγορία υλοποίηση,,en,εισαγωγής java.lang.reflect.Method,,en,εισαγωγής org.springframework.aop.MethodBeforeAdvice,,en,δημόσια τάξη LogBefore υλοποιεί MethodBeforeAdvice,,en,public void πριν,,en,στόχο την αντικείμενο,,en,Πριν Κλήση συγκρίνετε Μέθοδος,,en

package com.techalpine;

public class CompareIntImpl implements CompareInt{

public String compare(int a, int b){

αν (ένα>β)

{

return a ” is greater than” b;

}

αλλού

{

return “b is greater than a”;

}

}

}

Now we will write a simple advice to be called before calling the compare (int, int) μέθοδος. The advice will be discussed in details in the following chapters. Now you can imagine advice as a task which will be plugged into the application through xml configuration. And this will be called before the method is called. But there will not have any direct coding inside the implementation class. We will only take before advice for the implementation class.







package com.techalpine;

import java.lang.reflect.Method;

import org.springframework.aop.MethodBeforeAdvice;

public class LogBefore implements MethodBeforeAdvice{

public void before(Method method, Αντικείμενο[] args, Object target) {

System.out.println(“Before Calling the compare Method”);

}

}

Τώρα θα συζητήσουμε για το αρχείο ρυθμίσεων,,en,Test-AOP.xml,,en,Το αρχείο έχει τρία τμήματα,,en,Το πρώτο τμήμα είναι ο ορισμός συμβουλές φασόλια,,en,Το δεύτερο τμήμα προσδιορίζει την τάξη εφαρμογή,,en,Το τρίτο τμήμα ορίζει τη δέσμευση του συμβουλές με την τάξη εφαρμογή,,en,www.springframework.org/schema/beans/spring-beans-2.0.xsd,,en,Συμβουλές,,en,φασόλι id =,,en,beforeCall,,en,class =,,en,com.techalpine.LogBefore,,pt,Κατηγορία εφαρμογή,,en,compareImpl,,en,com.techalpine.CompareIntImpl,,pt,Μεσολάβησης Class Υλοποίηση,,en,συγκρίνω,,en,org.springframework.aop.framework.ProxyFactoryBean,,en,όνομα ιδιότητας =,,en,proxyInterfaces,,en,com.techalpine.CompareInt,,pt,interceptorNames,,en,ref φασόλια =,,en,Τώρα το τελευταίο μέρος είναι η CompareTest.java τάξη δοκιμή,,en,Φορτώνει τον ορισμό φασόλια, χρησιμοποιώντας XMLBeanFactory τάξη και, στη συνέχεια, κάλεσε το συγκρίνετε,,en,εισαγωγής org.springframework.beans.factory.BeanFactory,,en,εισαγωγής org.springframework.beans.factory.xml.XmlBeanFactory,,en (Test-AOP.xml)

The file has three sections

  • The first section is the advice bean definition
  • The second section defines the implementation class
  • The third section defines the binding of the advice with the implementation class

<φασόλια xmlns =”http://www.springframework.org/schema/beans”

xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=”http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.0.xsd”>

<!– Advices –>

<bean id = “beforeCall”

class = “com.techalpine.LogBefore” />

<!– Implementation Class –>

<bean id = “compareImpl”

class = “com.techalpine.CompareIntImpl ” />

<!– Proxy Implementation Class –>

<bean id = “compare”

class = “org.springframework.aop.framework.ProxyFactoryBean”>

<property name = “proxyInterfaces”>

<αξία>com.techalpine.CompareInt</αξία>

</περιουσία>

<property name = “interceptorNames”>

<list>

<αξία>beforeCall</αξία>

</list>

</περιουσία>

<property name = “target”>

<ref bean = “compareImpl”/>

</περιουσία>

</φασόλι>

</φασόλια>

Now the last part is the test class CompareTest.java. It loads the bean definition by using XMLBeanFactory class and then called the compare () μέθοδος.

package com.techalpine;

import org.springframework.beans.factory.BeanFactory;

import org.springframework.beans.factory.xml.XmlBeanFactory;

εισαγωγή org.springframework.core.io. *,,it,δημόσια τάξη CompareTest,,en,πόρος Πόρων = νέα FileSystemResource,,en,src / Test-AOP.xml,,en,BeanFactory εργοστάσιο = νέα XmlBeanFactory,,en,πόρος,,en,Με CompareInt =,,pt,Αθροιστής,,en,factory.getBean,,en,αποτέλεσμα String = com.compare,,en,αποτέλεσμα =,,en,αποτέλεσμα,,en,Η έξοδος της συγκρίνετε,,en,Μέθοδος κλήσης θα είναι ως εξής,,en,Πριν καλέσετε το συγκρίνουν τη μέθοδο,,en,είναι μεγαλύτερο από,,en,Άνοιξη AOP είναι πολύ χρήσιμο όταν προσπαθούμε να διαχωρίσει επιχειρηματικής λογικής από το σταυρό ανησυχίες κοπής,,en,Χρησιμοποιείται ευρέως σε διάφορες μορφές για να καλύψει διάφορες πτυχές,,en,AOP μπορεί επίσης να εφαρμοστεί και σε άλλες γλώσσες προγραμματισμού,,en;

public class CompareTest {

δημόσια στατική άκυρη κύρια(args String[]){

Resource resource = new FileSystemResource(“./src/Test-AOP.xml”);

BeanFactory factory = new XmlBeanFactory(resource);

CompareInt com = (Adder)factory.getBean(“compare”);

String result = com.compare(12,10);

System.out.println(“Result = ” + result);

}

}

The output of the compare () method call would be as follows

Before calling the compare Method

12 is greater than 10







Συμπέρασμα:

Spring AOP is very helpful when we try to separate business logic from cross cutting concerns. It is widely used in different forms to cover various aspects. AOP can also be implemented in other programming languages.

 

Tagged on: ,
============================================= ============================================== Buy best TechAlpine Books on Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Enjoy this blog? Please spread the word :)

Follow by Email
LinkedIn
LinkedIn
Share