Vaadin 7 on Grails 2.x
  • Introduction
  • Project setup
    • Command Line
    • IntelliJ IDEA
    • Eclipse
    • NetBeans
    • Plugin Configuration
    • Clean up
    • Best Practices
  • Database
    • GORM
      • Create Domain Model
      • Transactions
      • LazyInitializationException
      • Open Session In View I.
      • Open Session In View II.
      • Table Container
    • Groovy SQL
      • Create Sql
      • Execute SQLs
    • MyBatis
      • Configuration
      • Basics
    • JdbcTemplate
      • Create Beans
      • Usage
    • Clean Up With Alternatives
  • Architecture
    • Model View Presenter
  • Spring Autowiring
    • Create Simple Application
    • Application With Navigator
  • UI
    • Re-using GORM Validations
    • Async Push
    • Multiple application
    • SASS Compilation
    • Widgetset Compilation
  • Spring Security
    • Spring Security Dependency
    • Spring Security Basics
    • Secured Navigator
  • Localization
    • Localization Basics
    • Custom MessageSource
  • REST
    • Without using root URL
    • Using root URL for Vaadin app
  • Plugin development
    • Github
    • Development
Powered by GitBook
On this page
  • Step 1
  • Step 2
  • Step 3
  • Step 5

Was this helpful?

  1. Spring Autowiring

Create Simple Application

PreviousSpring AutowiringNextApplication With Navigator

Last updated 5 years ago

Was this helpful?

Example code is available on .

In this tutorial, we will create Vaadin application where we can use @Autowired annotation.

Step 1

We need to say the plugin that we want to do annotation based URL mapping. Comment out mapping from VaadinConfig.groovy to do that.

vaadin {
//    mapping = [
//            "/*": "app.MyUI"
//    ]
}

Step 2

Now we will create a dummy service ItemService that we will autowire in Vaadin code.

package app

import grails.transaction.Transactional

@Transactional
class ItemService {

    String serviceMethod() {
        return 'Value from service'
    }
}

Step 3

Use @VaadinUI annotation to map your UI class to URL.

package app

import com.vaadin.grails.ui.VaadinUI
import com.vaadin.server.VaadinRequest
import com.vaadin.ui.Label
import com.vaadin.ui.UI
import com.vaadin.ui.VerticalLayout
import org.springframework.beans.factory.annotation.Autowired

@VaadinUI(path = '/')
class MyUI extends UI {

    @Autowired
    ItemService itemService

    @Override
    protected void init(VaadinRequest r) {

        VerticalLayout layout = new VerticalLayout()
        layout.setMargin(true)

        String homeLabel = itemService.serviceMethod()

        Label label = new Label(homeLabel)
        layout.addComponent(label)

        setContent(layout)
    }
}

That is all, now you can run the application and ItemService will be autowired.

Step 5

Run the application grails run-app and open in a browser.

Running application with Navigator
github.com/vaadin-on-grails/spring-autowiring-basics
http://localhost:8080/spring-autowiring-basics