完整的springboot工程 | 您所在的位置:网站首页 › springbootthymeleafmybatispagehelper › 完整的springboot工程 |
spring-boot出乎意料的好用,本文给大家展示生产实践中怎么用spring-boot。 工程结构代码 收藏代码 whatsmars-spring-boot|-src |-java|-com.itlong.whatsmars.spring.boot Application.java BeanConfig.java UserConfig.java UserController.java UserService.java |-resources|-mapper User-mapper.xml|-static red.jpg|-templates index.html application.properties application-bean.xml application-dev.properties application-prod.properties application-test.properties log4j2.xml mybatis-config.xmlpom.xmlXml代码 收藏代码 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 whatsmars-spring-boot jar ${project.artifactId} http://maven.apache.org com.itlong.whatsmars.spring.boot.Application org.springframework.boot spring-boot-starter-parent 1.5.2.RELEASE org.mybatis.spring.boot mybatis-spring-boot-starter 1.1.1 org.springframework.boot spring-boot-starter-logging ch.qos.logback logback-classic org.springframework.boot spring-boot-starter-web ch.qos.logback logback-classic org.springframework.boot spring-boot-starter-actuator org.springframework.boot spring-boot-starter-logging org.springframework.boot spring-boot-starter-aop org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-log4j2 commons-dbcp commons-dbcp 1.4 mysql mysql-connector-java com.github.pagehelper pagehelper 4.1.6 org.springframework.boot spring-boot-starter-thymeleaf ${project.artifactId} src/main/resources true org.springframework.boot spring-boot-maven-plugin org.springframework springloaded 1.2.6.RELEASE xmlns="http:>application.propertiesProperties代码 收藏代码 #spring.profiles.active=prod#spring.profiles.active=devspring.profiles.active=testapplication-test.propertiesProperties代码 收藏代码 server.port: 80spring.session.store-type=redis server.session.timeout=14400#server.session.cookie.domain=${toutiao.domain} #server.session.cookie.http-only=true #server.session.cookie.path=/#监控 #management.port: 9900 #management.address: 127.0.0.1#server.contextPath=/userserver.tomcat.uri-encoding=UTF-8 server.tomcat.basedir=/data/wely/logsserver.tomcat.accesslog.directory=logs server.tomcat.accesslog.enabled=true server.tomcat.accesslog.pattern=common server.tomcat.accesslog.prefix=access_log server.tomcat.accesslog.suffix=.logspring.datasource.url=jdbc:mysql://127.0.0.1:3306/wely?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.tomcat.min-idle=10 spring.datasource.tomcat.max-idle=50 spring.datasource.tomcat.max-active=100 spring.datasource.tomcat.max-wait=10000 spring.datasource.tomcat.max-age=10000 spring.datasource.tomcat.test-on-borrow=true spring.datasource.tomcat.test-on-return=false spring.datasource.tomcat.test-while-idle=true spring.datasource.tomcat.time-between-eviction-runs-millis=5000 spring.datasource.tomcat.validation-query=SELECT 1mybatis.config-location=classpath:mybatis-config.xml# REDIS (RedisProperties) spring.redis.host=127.0.0.1 spring.redis.password=123456 spring.redis.pool.max-active=8 spring.redis.pool.max-idle=8 spring.redis.pool.max-wait=-1 spring.redis.pool.min-idle=1 spring.redis.port=6379 spring.redis.timeout=0spring.jackson.date-format=yyyy-MM-dd HH:mm:sstoutiao.domain=www.toutiao.im toutiao.loginCallback=http://${toutiao.domain}/user/login toutiao.logoutCallback=http://${toutiao.domain}/ toutiao.loginSuccessIndex=http://${toutiao.domain}/index.htmluser.welcome=Hello, World! user.noFilterUrl=/,/loginspring.thymeleaf.cache=falseapplication-bean.xml spring-boot追求无xml配置,但仍可以加载xml配置Xml代码 收藏代码 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd" default-autowire="byName"> id="userservice" class="com.itlong.whatsmars.spring.boot.userservice"> xmlns="http:>index.htmlHtml代码 收藏代码 xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> thymeleaf thymeleafth:text="${hello}"> th:inline="text"> xmlns="http:> Java代码 收藏代码 @SpringBootApplication @EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class}) @EnableConfigurationProperties({UserConfig.class}) public class Application {public static void main(String[] args) { SpringApplication.run(Application.class, args); }}注意,Application类所在包及子包下的所有类默认均在ComponentScan非为内。 Java代码 收藏代码 @Controller public class UserController {@Autowired private UserConfig userConfig;@RequestMapping("/") public String home(Map map) { map.put("hello", "Hi, boy!"); return "index"; } @RequestMapping("/do") @ResponseBody public String doSth() { return userConfig.getWelcome(); } } ,object>Java代码 收藏代码 @ConfigurationProperties(prefix="user") public class UserConfig {private String welcome;private List noFilterUrl; public String getWelcome() { return welcome; } public void setWelcome(String welcome) { this.welcome = welcome; } public List getNoFilterUrl() { return noFilterUrl; } public void setNoFilterUrl(List noFilterUrl) { this.noFilterUrl = noFilterUrl; } }Java代码 收藏代码 @Configuration @ImportResource(locations={"classpath:application-bean.xml"}) public class BeanConfig { }Java代码 收藏代码 public class UserService {private final Logger logger = LogManager.getLogger(getClass());public UserService() { logger.info("UserService init..."); System.out.println("UserService init..."); } }Xml代码 收藏代码 /data/wely/logs name="logpath"> onMismatch="DENY"/> level="debug" onmatch="accept"> filePattern="${logPath}/$${date:yyyy-MM-dd}/debug-%d{yyyy-MM-dd}-%i.log"> onMismatch="ACCEPT"/> onMismatch="DENY"/> level="debug" onmatch="accept"> level="info" onmatch="deny"> filePattern="${logPath}/$${date:yyyy-MM-dd}/info-%d{yyyy-MM-dd}-%i.log"> onMismatch="NEUTRAL"/> level="warn" onmatch="deny"> filePattern="${logPath}/$${date:yyyy-MM-dd}/warn-%d{yyyy-MM-dd}-%i.log"> onMismatch="NEUTRAL"/> level="error" onmatch="deny"> filePattern="${logPath}/$${date:yyyy-MM-dd}/error-%d{yyyy-MM-dd}-%i.log"> filePattern="${logPath}/$${date:yyyy-MM-dd}/trace-%d{yyyy-MM-dd}-%i.log">name="userservice" filename="${logpath}> name="rollingfiletrace" filename="${logpath}> name="rollingfileerror" filename="${logpath}> name="rollingfilewarn" filename="${logpath}> name="rollingfileinfo" filename="${logpath}> name="rollingfiledebug" filename="${logpath}> name="console" target="system_out"> name="com.itlong.whatsmars.spring.boot.userservice" level="info" additivity="false"> level="info"> status="debug"> 三种启动方式: Application.main() mvn spring-boot:run java -jar whatsmars-spring-boot.jar原文链接:[ |
今日新闻 |
推荐新闻 |
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 |