å¦ä½ç¨springbootå建mavençä¾èµå·¥ç¨
æè¿å ¬å¸è¿ç¨springbootæ建项ç®ï¼ç¡®å®æ¯sshæ建è¦å¿«å¾å¤ãspringbootå®æ¹å¦ä¹ ç½ç«
1.é¦å è¦ä¸è½½mavenï¼ç¨maven管ç项ç®å¾æ¹ä¾¿ï¼ä¸è½½å®mavené 置好ç¯å¢ï¼mavenæå°±ä¸ç»è¯´äºã
2.å建ä¸ä¸ªmaven项ç®ï¼pom.xmlæ件éé¢åè¿äº:
<modelVersion>4.0.0</modelVersion>
<groupId>springboot</groupId>
<artifactId>testSpringBoot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>testSpringBoot</name>
<packaging>jar</packaging>
<!-- 继æ¿ç¶å -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.3.RELEASE</version>
<relativePath></relativePath>
</parent>
<!-- spring-bootçwebå¯å¨çjarå -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--jpaçjarå ï¼æä½æ°æ®åºçï¼ç±»ä¼¼hibernate-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!--mysql驱å¨-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!--thymeleaf模æ¿jarï¼æ¯å¾ä¸éçhtmlæ°æ®ä¼ éåå¼ï¼ç±»ä¼¼jspçjstl-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<!--mavençæ件-->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
<!-- é ç½®javaçæ¬ ä¸é ç½®çè¯é»è®¤ç¶ç±»é ç½®çæ¯1.6-->
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
3.å建çæ件ç®å½å¦å¾:
4.å¨com.boot(å³æå¤å±ç®å½æ件)ä¸åä¸ä¸ªå¦ä¸mainæ¹æ³:
package com.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,下n下工作室源码下载 args);
}
}
5.å¨com.boot.webä¸å建ä¸ä¸ªç±»å¦ä¸:
package com.boot.web;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MainController {
// @RequestMapping("")
// public String index(){
// return "examples/index";
// }
@RequestMapping("/")
@ResponseBody
String home() {
return "Hello World!";
}
}
@RequestMapping @ResponseBody
è¿ä¸¤ä¸ªæ³¨è§£é½æ¯springMVCç,ä¸æå¾å¯ä»¥çspringMVC
6.å¨resourcesä¸å¢å ä¸ä¸ªapplication.propertiesæ件
æ件å 容å¦ä¸é ç½®:
spring.datasource.platform=mysql
spring.datasource.url=jdbc:mysql://localhost/springboot?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&autoReconnect=true&failOverReadOnly=false
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driverClassName=com.mysql.jdbc.Driver
# Advanced configuration...
spring.datasource.max-active=
spring.datasource.max-idle=6
spring.datasource.min-idle=2
spring.datasource.initial-size=6
#create table
spring.jpa.hibernate.ddl-auto=validate
server.port=
server.session-timeout=
server.tomcat.uri-encoding=UTF-8
spring.thymeleaf.prefix=classpath:templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
该æ件çé ç½®å¯ä»¥åèspringbootçå®ç½
该æ件çå ¨é¨åæ°é ç½®ï¼å¦ä¸(æèªå®ç½)
# ===================================================================
# COMMON SPRING BOOT PROPERTIES
#
# This sample file is provided as a guideline. Do NOT copy it in its
# entirety to your own application. ^^^
# ===================================================================
# ----------------------------------------
# CORE PROPERTIES
# ----------------------------------------
# SPRING CONFIG (ConfigFileApplicationListener)
spring.config.name= # config file name (default to 'application')
spring.config.location= # location of config file
# PROFILES
spring.profiles.active= # comma list of active profiles
# APPLICATION SETTINGS (SpringApplication)
spring.main.sources=
spring.main.web-environment= # detect by default
spring.main.show-banner=true
spring.main....= # see class for all properties
# LOGGING
logging.path=/var/logs
logging.file=myapp.log
logging.config= # location of config file (default classpath:logback.xml for logback)
logging.level.*= # levels for loggers, e.g. "logging.level.org.springframework=DEBUG" (TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF)
# IDENTITY (ContextIdApplicationContextInitializer)
spring.application.name=
spring.application.index=
# EMBEDDED SERVER CONFIGURATION (ServerProperties)
server.port=
# JACKSON (JacksonProperties)
spring.jackson.date-format= # Date format string (e.g. yyyy-MM-dd HH:mm:ss), or a fully-qualified date format class name (e.g. com.fasterxml.jackson.databind.util.ISODateFormat)
spring.jackson.property-naming-strategy= # One of the constants on Jackson's PropertyNamingStrategy (e.g.
# THYMELEAF (ThymeleafAutoConfiguration)
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html # ;charset=<encoding> is added
spring.thymeleaf.cache=true # set to false for hot refresh
# FREEMARKER (FreeMarkerAutoConfiguration)
spring.freemarker.allowRequestOverride=false
spring.freemarker.cache=true
spring.freemarker.checkTemplateLocation=true
spring.freemarker.charSet=UTF-8
spring.freemarker.contentType=text/html
spring.freemarker.exposeRequestAttributes=falseshell.ssh.keyPath=
shell.ssh.port=
shell.telnet.enabled= # telnet settings ...
shell.telnet.port=
shell.auth.jaas.domain= # authentication settings ...
shell.auth.key.path=
shell.authwww.meidiyazx.com/sitemap.txtname=
shell.authwww.meidiyazx.com/sitemap.txtpassword=
shell.auth.spring.roles=spring.freemarker.exposeSessionAttributes=false
spring.freemarker.exposeSpringMacroHelpers=false
spring.freemarker.prefix=
spring.freemarker.requestContextAttribute=
spring.freemarker.settings.*=
spring.freemarker.suffix=.ftl
spring.freemarker.templateLoaderPath=classpath:/templates/ # comma-separated list
spring.freemarker.viewNames= # whitelist of view names that can be resolved
# GROOVY TEMPLATES (GroovyTemplateAutoConfiguration)
spring.groovy.template.cache=true
spring.groovy.template.charSet=UTF-8
spring.groovy.template.configuration.*= # See Groovy's TemplateConfiguration
spring.groovy.template.contentType=text/html
spring.groovy.template.prefix=classpath:/templates/
spring.groovy.template.suffix=.tpl
spring.groovy.template.viewNames= # whitelist of view names that can be resolved
# VELOCITY TEMPLATES (VelocityAutoConfiguration)
spring.velocity.allowRequestOverride=false
spring.velocity.cache=true
spring.velocity.checkTemplateLocation=true
spring.velocity.charSet=UTF-8
spring.velocity.contentType=text/html
spring.velocity.dateToolAttribute=
spring.velocity.exposeRequestAttributes=false
spring.velocity.exposeSessionAttributes=false
spring.velocity.exposeSpringMacroHelpers=false
spring.velocity.numberToolAttribute=
spring.velocity.prefix=
spring.velocity.properties.*=
spring.velocity.requestContextAttribute=
spring.velocity.resourceLoaderPath=classpath:/templates/
spring.velocity.suffix=.vm
spring.velocity.viewNames= # whitelist of view names that can be resolved
# INTERNATIONALIZATION (MessageSourceAutoConfiguration)
spring.messages.basename=messages
spring.messages.cacheSeconds=-1
spring.messages.encoding=UTF-8
# SECURITY (SecurityProperties)
security.user.name=user # login username
security.user.password= # login password
security.user.role=USER # role assigned to the user
security.require-ssl=false # advanced settings ...
security.enable-csrf=false
security.basic.enabled=true
spring.batch.schema= # batch schema to load
# AOP
spring.aop.auto=
# GIT INFO
spring.git.properties= # resource ref to generated git info properties file
7.æ¾å°com.bootä¸çApplication以java Applicationæ¹å¼å¯å¨ï¼ç¶åæå¼æµè§å¨è¾å ¥localhost:å°±ä¼åºç°Hello World!
è¿æ ·ä¸ä¸ªç®åçwebå¼åå°±æ建好äºã
2024-11-14 12:40
2024-11-14 12:35
2024-11-14 11:13
2024-11-14 10:55
2024-11-14 10:08