跳至主要内容

Create a Spring project from Spring ToolSuite

The Spring company, SpringSource provides a full stack solution for Spring development, including excellent IDE support, SpringSource provides an Eclipse based IDE to speed up the development of Spring project.

Install Spring ToolSuite

You can download a copy of Spring ToolSuite from SpringSource, and install it into your local disk.
Alternatively, you can get a copy of the JEE bundle from Eclipse website and install Spring ToolSuite plugin manually from Eclipse Marketplace.
  1. Download the newest Eclipse JEE Bundle from the Eclipse website.
  2. Extract the files from the zip archive into your local disk.
  3. Start up Eclipse IDE.
  4. Open Eclpse Marketplace from Help menu in the IDE menu bar.
  5. Search SpringSource to find the Spring ToolSuite plugin.
  6. Click Install button and wait the installation done.
  7. Restart IDE according to the prompt, and apply the change.
Note: In the further content, I will use the words IDE or Eclipse, it refers to Spring ToolSuite or Eclipse IDE with Spring ToolSuite plugin installed.
Some Maven plugin such as APT needs a JDK instead of JRE at runtime.
Open Preference dialog, type JRE in the query text box to find the JRE you are using, change the JRE location to your JDK's location.
Also do not forget adjust the STS.ini, add -vm parameter, place it above the -vmargs. An example here.
-vm
D:/jdk7/bin/javaw.exe
...
-vmargs
...
Optionally, install the m2e wtp plugin from Eclipse Marketplace to improve the web application support in Eclipse IDE.
  1. Open the Eclipse Marketplace from Help menu of the Eclipse main menu.
  2. Type wtp to search the Eclipse WTP related plugins.
  3. Select Maven Integration for Eclipse WTP(incubation) and click Install button.
  4. Wait for the installation done, follow the Eclipse prompt and restart Eclipse to apply the plugins.

Create a Roo based project

Spring Roo is supported in Spring ToolSuite. You can create a Roo based Spring project from Eclipse directly.
  1. Open the Spring Roo Project creation wizard.
    You can open the Roo project wizard from the SpringSource Dashboard(the "Home" page of Spring ToolSuite),
    Open Roo project from SpringSource Dashboard
    or follow the New project wizard. It is fairly easy work.
    Create Roo project from new project wizard
  2. Fill the basic project info in the new Roo project dialog.
    Create Roo project from new project wizard
  3. Click Finish button to complete the creation.
After you created such one project, Eclipse should open a Roo shell view for you.
Create Roo project from new project wizard
Yes, Spring ToolSuite integrate a command line interface in IDE directly, you can use it freely, just like the one in your system terminal.

Setup essential artifacts

You can type the addon command the Roo Shell view and use IDE code assistance shortcuts( CTRL+SPACE by default) to get the available options.
Create Roo project from new project wizard
Now you can follow the steps in last post and try to create a new Entity Conference in the Eclipse based Roo console.
Open the entity class Conference you have just created in the Roo console, try to add a new property name, and save it. Eclipse will synchronize the change set to the Roo related aspect files, you can some logging info in the Roo console.
Open Conference_Roo_JavaBean.aj in the same package, you will find the getter and setter of the name property are generated.
privileged aspect Conference_Roo_JavaBean {
    
    public String Conference.getName() {
        return this.name;
    }
    
    public void Conference.setName(String name) {
        this.name = name;
    }
}
It is magic.
Follow the steps in last post and add other artifacts yourself.

Run the project

A developer edition of VMware vFabric Server is shipped with Spring ToolSuite.
Run project in VMware vFabric Server is really simple, just drag the project root node to the server instance and release it.
The project will be deployed into the server.
Create a cloudfoudry server instance
Open browser, go to http://localhost:8080/.
Create a cloudfoudry server instance

评论

此博客中的热门博文

Build a Reactive application with Angular 5 and Spring Boot 2.0

I have created a post to describe Reactive programming supports in Spring 5 and its subprojects, all codes of this article are updated the latest Spring 5 RELEASE, check spring-reactive-sample under my Github account.
In this post, I will create a simple blog system, including:
A user can sign in and sign out.An authenticated user can create a post.An authenticated user can update a post.Only the user who has ADMIN role can delete a post.All users(including anonymous users) can view post list and post details.An authenticated user can add his comments to a certain post. The backend will be built with the latest Spring 5 reactive stack, including:
Spring Boot 2.0, at the moment the latest version is 2.0.0.M7Spring Data MongoDB supports reactive operations for MongoDBSpring Session adds reactive support for WebSessionSpring Security 5 aligns with Spring 5 reactive stack The frontend is an Angular based SPA and it will be generated by Angular CLI.
The source code is hosted on Github, …

Activating CDI in JSF 2.3

Activating CDI in JSF 2.3 When I upgraed my Java EE 7 sample to the newest Java EE 8, the first thing confused me is the CDI beans are not recoganized in Facelects template in a JSF 2.3 based web applicaiton, which is working in the development version, but in the final release version, they are always resolved as null. I filed an issue on Mojarra and discussed it with the developers from communities and the JSF experts.
According to the content of README, In a JSF 2.3 application, to activate CDI support, declaring a 2.3 versioned faces-config.xml and adding javax.faces.ENABLE_CDI_RESOLVER_CHAIN in web.xml is not enough, you have to declare @FacesConfig annotated class to enable CDI.
Here is the steps I created a workable JSF 2.3 applicatoin in Java EE 8.
Create a Java web application, this can be done easily by NetBeans IDE, or generated by Maven archetype, for exmaple.
$ mvn archetype:generate -DgroupId=com.example -DartifactId=demo -DarchetypeArtifactId=maven-archetype-w…

JSF 2.3:Websocket support

Websocket support One of the most attractive features is JSF 2.3 added native websocket support, it means you can write real-time applications with JSF and no need extra effort.
To enable websocket support, you have to add javax.faces.ENABLE_WEBSOCKET_ENDPOINT in web.xml.
<context-param> <param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name> <param-value>true</param-value> </context-param> Hello Websocket Let's start with a simple example.
@ViewScoped@Named("helloBean") publicclassHelloBeanimplementsSerializable { privatestaticfinalLoggerLOG=Logger.getLogger(HelloBean.class.getName()); @Inject@PushPushContext helloChannel; String message; publicvoidsendMessage() { LOG.log(Level.INFO, "send push message"); this.sendPushMessage("hello"); } privatevoidsendPushMessage(Objectmessage) { helloChannel.send(""+ message +" at &…