to guess how you want to configure spring based on the added jar dependency. Because Spring-boot-starter-web adds Tomcat and spring MVC, Auto-configuration will assume that you are developing a web app and setting up spring accordingly. Starter POMs and Auto-configuration: The purpose of design auto-configuration is to better use "Starter POMs", but these two concepts are not directly linked. You are free to choose a jar dependency other than starter Poms, and spring boot will still do its best
The "Background" Spring-boot project, packaged as an executable jar, has two classes with the Main method in the project and all use @SpringBootApplication Note (or another scenario: you have two main methods and your class does not use @springbootapplication annotations), pom.xml as followsplugin> groupId>Org.springframework.bootgroupId> Artifactid>Spring-boot-maven-pluginArtifactid> version>1.5.3
@Configuration, @EnableAutoConfiguration, @ComponentScan。 Since these annotations are generally used together, spring boot provides a unified annotation
@SpringBootApplication。
@SpringBootApplication= (default property)
@Configuration + @EnableAutoConfiguration + @ComponentScan。
@SpringBootApplication
Public
classApplicationmain {
Public
Static
voidMain (strin
I. List of annotations (annotations)@SpringBootApplication: Contains @componentscan, @Configuration, and @enableautoconfiguration annotations. Where @componentscan let spring boot scan to the configuration class and add it to the program context.
@Configuration an XML configuration file that is equivalent to spring and can be checked for type safety using Java code.
@EnableAutoConfiguration automatic configuration.
@ComponentScan component scans to au
I. List of annotations (annotations)@SpringBootApplication: Contains @componentscan, @Configuration, and @enableautoconfiguration annotations. Where @componentscan let spring boot scan to the configuration class and add it to the program context.
@Configuration an XML configuration file that is equivalent to spring and can be checked for type safety using Java code.
@EnableAutoConfiguration automatic configuration.
@ComponentScan component scans to au
(autowiredannotationbeanpostprocessor.java:585) ... + More That is to say, can't find the realization of Articledao, what reason is this? As we've seen in the previous blog post, @springbootapplication has inherited @componentscan, which by default only scans packages and sub-packages where the application class is located. Therefore, for the above error, in addition to keeping the application class in the DAO's parent package, you can also specify
", method = RequestMethod. GET) public User findByUserAge (@ RequestParam (value = "userAge", required = true) int userAge) {System. out. println ("START querying... "); return userService. findUserById (userAge );}}
3.5 Application main program
SpringApplication is a class used to start Spring applications from the main method.
By default, it performs the following steps:
1. Create an appropriate ApplicationContext instance (depending on classpath ).
2. Register a CommandLinePropertySource to u
is not required if maven's spring-boot: run is used.
org.springframework.boot
spring-boot-maven-plugin
4. Write the program below. We need a startup class, and then let spring boot automatically configure the spring configurations in the startup class declaration, for example: @ SpringBootApplication, to make the program ru
recommended location for Application.java:Finally tried to modify the next application on the note, I originally copied the official code with the @controller and @EnableAutoConfiguration, replaced by @ Springbootapplication annotations , unexpectedly can scan to controller Really depressed incredibly is this reason, official document says @controller and @EnableAutoConfiguration and @springbootapplication
Web development uses controllers to do most of the work, but we may also use Servlets, Filter, Listener, Interceptor, and so on.When Spring-boot is used, the embedded servlet container registers all listeners of the servlet, filter, and servlet specifications (such as the Httpsessionlistener Listener) by scanning annotations.The main Servlet of Spring boot is dispatcherservlet, and its default url-pattern is "/". Maybe we need to define more servlets in our application, how do we use Springboot
run
First, use idea to create a new projectOpen the project directory and create a new moudle, named Firststream,pom file, as followsSecond, add Message Handler, Building and runcom.cnblogs.hellxzAdd the Startup class under the package, and add@SpringBootApplication@EnableBinding(Sink.class)public class FirstStreamApp { public static void main(String[] args) { SpringApplication.run(FirstStreamApp.class, args); } @StreamListener(S
Idea development tool, with STS suite by default;2) New project, Spring Initializer, Next, fill project information, tick Web, fill in the Item name and path, finishWhen Maven finishes, a simple Springboot project is built.4. TestingWe write a controller under the ClasspathImport org.springframework.web.bind.annotation.RequestMapping; Import Org.springframework.web.bind.annotation.RestController; @RestController Public class Samplecontroller { = "Hello") public String Hello () {
org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RestController;
@RestController
Public class Hellocontroller {
@RequestMapping ("/hello")
Public String Hello () {
return "Hello,this is a springboot demo";
}
}
7. Automatically generated by the program springbootdemoapplication, there will be a @springbootapplication annotation, this note is used to indicate that this class
Reference.1. Problems encountered:-Bind:address already in use appears because the current project is running, so you can stop the current project. CMD in the command Netstat-nao view all occupied ports and PID number, in Task Manager, the corresponding PID process is stopped.[Email protected] AnnotationsIn the official code, the controller and main function are written in a class, so you don't need to springbootapplication this annotation, write it i
There are two ways to build a spring boot project Gradle, mavenMaven modePom.xml
spring-boot-starter: core modules, including automatic configuration support, logs, and Yaml
spring-boot-starter-test: Test modules, including JUnit, Hamcrest, Mockito
Spring-boot-starter-web:web Module
Gradle WayBuild.gradleCompile ("Org.springframework.boot:spring-boot-starter-web:1.4.1.build-snapshot")Springboot Start-up classImport org.springframework.boot.SpringAppli
under the root package path.
If our project is like the code structure proposed by spring boot, the application class is placed under the root package path. Then we can use @springbootapplication to replace the three annotations above.
Package com.example.myproject;
Import org.springframework.boot.SpringApplication;
Import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
First, create Eurekaserver
1, create the first server, create a springboot project
1 Java code is as follows, using port 7070:
@EnableEurekaServer
@SpringBootApplication
@RestController public
class Eurekaserverapplication {
@RequestMapping ("/exec") public
String Execinfo () {
System.out.println ("Server01");//danielinbiti return
"Server01";
}
public static void Main (string[] args) {
springapplication.run (eurekaserverapplicati
Reference:
Mu network Liao Shi Brother: Two hours to learn Springboot
http://www.imooc.com/learn/767
1. Open idea, create new project, select Spring INITIALIZR
2. Input artifact
3. Tick the Web
4. Click Finish
5. Enter the project, you can delete the following content
Pom.xml file:
6. Create a Hellocontroller
Package com.example;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.bind.annotation.RestController;
@RestController publ
Enable automatic configuration of the spring application context, and try to guess and configure the beans you might need. Automatic configuration classes are typically based on classpath and defined bean applications. For example, if you have Tomcat-embedded.jar in your classpath, you might want a tomcatembeddedservletcontainerfactory ( Unless you define your own embeddedservletcontainerfactory bean).
When Springbootapplication is used, the automatic
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.