Scala and spring: Powerful alliances

Source: Internet
Author: User

Scala is an excellent programming language that seamlessly blends concise, clear syntax with object-oriented and functional programming paradigms and is fully compatible with Java, so Scala can use Java APIs and many frameworks that Java developers know well. In this case, we can improve and simplify the existing Java framework through Scala. In addition, Scala's learning threshold is also very low, because we can easily integrate it into the "well-known Java world."

This article will describe how to integrate spring into one of the most popular frameworks in the world through Scala. Spring not only supports efficient programming paradigms such as dependency injection and aspect-oriented programming, but also provides a large amount of glue code to interact with frameworks such as Hibernate, TopLink, and JEE environments, which ensures that Scala is smoothly integrated into the enterprise, without a doubt, This is where spring's success lies.

To clearly illustrate the integration principles of Scala and spring, this article will use a simple example application. This application will use Scala, spring, and HIBERNATE/JPA, whose domain model is shown in the following illustration:

The domain model shows a simplified social network application: People can link to each other.

First step

The following explanations will be based on the domain model. First, we introduce how to implement a generic DAO, and use Scala to implement a specific DAO for the person entity by HIBERNATE/JPA, whose name is Persondao, which encapsulates the crud operations. As shown below:

val p1 = new Person(“Rod Johnson”)
val p2 = dao.findByName(“Martin Odersky”)
p1.link(p2)
personDao.save(p1)

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.