StaticStringGetchat_collprefix() {returnChat_collprefix; }@Value("${mongo.config.collprefix}") Public void Setchat_collprefix(String Chat_collprefix) {Mongoconfig.Chat_collprefix= Chat_collprefix; }}YML configuration file definitionUse profiles to specify different configurations for different environments. Active specifies an active environment, such as Dev or prodSpring: Application: Name:TextmlProfiles: Active:Dev---Spring: Profiles:Dev, default,testMONGO: Config: Username: "XX
("${face_api_key}") 2private String api_key; 3 @Value ("${face_api_secret}") 4private String Api_secret;Note: When using this annotation, a class that uses @value, if referenced by another class as an object, must use the injection method instead of new. This is important, and I'm just being caught in this hole.@ExceptionHandler (exception.class): Use the method above to indicate that you have encountered this exception to perform the following methods.@ControllerAdvice contains
Timed tasks, asynchronous tasksI. Scheduled Tasks1. Steps:1: Write @EnableScheduling annotations on the startup class2: Write @component on the class for which you want to schedule tasks3: Write @Scheduled(fixedrate= milliseconds) on the method to be executed on a timed basis.2. ExampleMain class@SpringBootApplication@EnableScheduling // turn on timed tasks Public class mainapplication { publicstaticvoid main (string[] args) { Springappli
; Import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication Public class Application { publicstaticvoid main (string[] args) { Springapplication.run (Application. class , args);} }Springbootapplication is a handy note that adds all of the following:
@Configuration to mark the class as the source of the bean definition for the application contex
the class, the simplest and most intuitive, the A injection:While intuitive, the need for batch injection is a bit cumbersome and @Import provides advanced features:ImportselectorImportselector is an interface that has only one method:String[] selectImports(AnnotationMetadata importingClassMetadata);The return value is the type full class name that needs to be injected, and the input parameter refers to @Import all of the annotation information, such as an implementation class:public class MyIm
# Display on the address bar using an IP address instance-id:config-7101.comSubsequent configuration files only need to take into account the "Instance-id" the difference can be;5, "microcloud-config-*" Modify the Program startup class, append Eureka client annotations: PackageCn.study.microcloud;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.autoconfigure.SpringBootApplication;ImportOrg.springframework.cloud.config.server.EnableConfigServer;Importorg.spr
1 Creating a Service registration centerHere, the component I need to use is spring Cloud Netflix Eureka, Eureka is a service registration and Discovery module.1.1 Creating the Model project as a service registration center Eureka-serverProject structurePom.xmlxsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > for Spring bootImport1.2 Start the Service registration center Eureka-serverSpringboot Startup class PackageCom.seawaterbt.cloud.eurekas
{
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-bo
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.j
).
。 The group or organization to which the project belongs. Typically expressed as a reverse domain name.
。 The name of the project library artifact to give (for example, the name of its jar or war file).
。 The version of the project being built.
-How to package the project. For JAR file packaging, the default is "jar". Use "war" to package the war file.
4. Adding a startup classTo create a package under the Src/main/java path, I named Com.demo. Under the package, create a
. Springframework.boot.SpringApplication; Import org. Springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplicationPublicclass appapplication { publicstaticvoid main (string[] args) { Springapplication.run (appapplication. class , args);} }The main entry for the Spring Boot project is a main function, and the benefit is that you can run the project in the IDE like a normal application, and it's easy to debug@SpringBootApplic
..."); ReTurn Userservice.finduserbyid (userage); }}3.5 Application Main ProgramSpringapplication is the class used to start the spring app from the main method.By default, it performs the following steps:1. Create an appropriate ApplicationContext instance (depending on the classpath).2. Register a commandlinepropertysource to use the command-line arguments as spring properties.3. Refresh application context to load all singleton beans.4. Activate all Commandlinerunner beans.Start the class di
What is BOOTNETTYRPC?BOOTNETTYRPC is an RPC framework implemented with Netty for spring boot projects and supports spring Cloud. Currently supported versions are Spring Boot 1.5.x,spring cloud versions D and E.How to use?It is divided into local startup and combined with spring cloud launch. See example case, now the local case to illustrate, Spring cloud case omitted.The BOOTNETTYRPC includes the server side and client side.Server SideAdd dependencies to the Pom file:In the spring boot start Pr
customizations are easily added declaratively. To do this, we use @springbootapplication on the main class and convert the primary method to start it, just like in any spring boot application. Finally, we move the resttemplate to a Commandlinerunner callback function to be executed at startup by spring Boot:Src/main/java/hello/application.java PackageHello;ImportOrg.slf4j.Logger;Importorg.slf4j.LoggerFactory;ImportOrg.springframework.boot.CommandLine
Create one of the simplest springboot applications @SpringBootApplication (Exclude={datasourceautoconfiguration.class,hibernatejpaautoconfiguration.class}) public Class DemoApplication {@Beanpublic Runnable Creatrunnale () {return () {System.out.println ("Springboot is Running") ;};} public static void Main (string[] args) {Configurableapplicationcontext contxt = Springapplication.run ( Demoapplication.class, args); Contxt.getbean (Runnable.class). R
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.