JAVA8+SPRING+ANGULARJS Project Application
Recently there has been writing an e-order business website that uses JAVA8,SPRING,ANGULARJS to share the technology used in the project with everyone.
The first time to write a blog, where there is no need to correct the correction, please contact.
Because the project is what I do to others can not provide the source code forgive me, I do my best to let everyone understand.
First, starting with the construction of the project, I used the Gradle build project, which uses the version 2.4.
Idea 14 for the development environment, the project database uses SQL SERVER.
Spring Boot Technical Document: Http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle
You can see all the boot configuration and technology development here, for the English bad suggestions about the general understanding, I will slowly write, slowly understand, I know.
How to bring spring boot into the project is as follows:
Take a look at the Gradle Spring Boot configuration, with the latest version 1.2.3
Buildscript {
ext {
Springbootversion = "1.2.3.RELEASE"
}
repositories {
Mavenlocal ()
Jcenter ()
Maven {URL "http://repo.spring.io/snapshot"}
Maven {URL "Http://repo.spring.io/milestone"}
Maven {URL "http://repo.spring.io/plugins-release"}
}
dependencies {
Classpath ("Org.springframework.boot:spring-boot-gradle-plugin:${springbootversion}")
Classpath ("Org.springframework:springloaded:${springbootversion}")
Classpath ("org.springframework.build.gradle:propdeps-plugin:0.0.6")
}
}
Apply plugin: "Java"
Apply plugin: "Spring-boot"
This is a Gradle basic build.gradle configuration file. You can go to the Gradle website to learn more about using it, the same functionality as MAVEN tools. Spring is built to support these two plugins.
To configure the spring components that our project uses:
It is in the Build.gradle file code below
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
testCompile("org.springframework.boot:spring-boot-starter-test")
}
We look at the contents of dependencies, compile is gradle inside a binding resource method, which can take the resource bundle we need and dependencies to load the project inside. If you use IDEA14 it will automatically help you configure, reference the class, everything is so simple.
First we add spring's spring-boot-starter-web component to the project.
Using Spring boot:
Spring boot is a high-integration spring management tool that coordinates spring components and allows you to spend less time configuring spring.
First we create a Application.java class under the project root package src/main/java/com/demo/, which should look like this:
@SpringBootApplication
@EnableScheduling
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@SpringBootApplication This is the Spring boot portal.
We write an entity Bean,src/main/java/com/demo/greeting.java as follows:
package com.demo;
public class Greeting {
private final long id;
private final String content;
public Greeting(long id, String content) {
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
Next we write a simple controller Controller,src/main/java/com/demo/greetingcontroller.java as follows:
package com.demo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.atomic.AtomicLong;
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value = "name", defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}
@RestController indicates that the controller is a rest controller, then it returns not our common view object, it will automatically put the object JSON, which is the spring default, followed by how to return other types (xml,excel,file)
Here we have written a simple spring boot application.
Run the Spring boot app:
In idea we can directly run with the right click of the application class, but we do not recommend it because it runs as you just run the local directory configuration and does not use spring boot.
We use Gradle to build so we recommend that you use Gradle to run your project. On the right side of idea you will find the Gradle display window. Just like we started with the Spring boot component already applied, Gradle config file build.gradle inside.
Apply plugin: ' java ' Apply plugin: ' idea ' Apply plugin: ' Spring-boot '
So we should be able to find the application program component in Gradle's tasks. These are usually the case:
And we click Bootrun to run it.
Next we visit in the browser
That should be the case. Indicates that our simple spring boot run was successful.
Next time I'll go into more detail, spring boot, Spring security,spring data, and its rest and JPA. For the JAVA8 used in the project will also involve some
Thank you, the first time to write a blog, rarely to write a blog, not so detailed, if you do not understand and questions please leave me a message, I will be the first time to reply to you.
If you are also interested in Java, welcome to explore together. Let's get here today.
Tags: java, spring, spring boot
Java8,spring,angularjs on the project