Simplifying Spring (5)--reducing unnecessary interface-based programming

Source: Internet
Author: User
Tags aop interface
Programming
As we all know, spring is a proponent of interfacing programming. But there are some service categories, such as Saleordermanager and Saleordermanagerimpl, with only 5% chance of another IMPL implementation.      95% time the two brothers stand together, just like C + +. H and. cpp, increased maintenance of the cumbersome, so just start with spring when you want to remove it, today accidentally in Group chat dynamic agent, is to understand the truth, thank sparkle:)    IOC is not enforcing interfaces, it is these service classes that typically use spring's declarative transaction mechanism, and declarative transaction mechanisms are implemented using spring AOP. Then look at spring AOP, mixed with Java dynamic proxies and CGLIB2, because Java dynamic proxies are ideal for AOP, but only for interfaces.    If you are based on class, Spring AOP uses Cglib to generate the subclass of the target class to implement AOP, quite realistically.    So, as long as we specify that AOP can be implemented using CGLIB with declarative transaction beans, it is not programming on an interface. The specified method is to set Proxytargetclass to true. eg.

<bean id= "Baseservice" class= "Org.springframework.transaction.interceptor.TransactionProxyFactoryBean"        Abstract= "true" > <property name= "TransactionManager" > <ref bean= "TransactionManager"/>        </property> <property name= "Proxytargetclass" > <value>true</value> </property> .... </bean>

This efficiency issue has also been discussed, because these service beans are single cases and the efficiency should not be affected.

Related articles: 1. Simplify spring--configuration file 2. Simplify the Spring--view Layer 3. Simplify the Spring--model layer 4. Simplifying Spring Controller to the simplest of all MVC schemes 5. Simplifying spring--reducing unnecessary interface programming


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.