一、springboot项目的简单使用
2017-07-05 09:26
741 查看
接着上篇搭建好项目之后,开始使用项目
application.properties代码:
这里贴上我项目的配置文件,配置springboot,配置数据库,配置redist,配置kafka
二、写一个项目的启动类
注意@enablescheduling 是定时任务,没有定时任务可以把此注解去掉
@EnableAutoConfiguration注释,此注释自动载入应用程序所需的所有Bean——这依赖于Spring Boot在类路径中的查找。
@EnableTransactionManagement注释,它能够声明事务管理
@SpringBootApplication注解,它包括三个注解:
@Configuration:表示将该类作用springboot配置文件类。
@EnableAutoConfiguration:表示程序启动时,自动加载springboot默认的配置。
@ComponentScan:表示程序启动是,自动扫描当前包及子包下所有类。
@EnableJpaRepositories注解用于Srping JPA的代码配置 本项目操作数据访的方式是利用JPA的方式操作
代码:package org.uz.dxt;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableScheduling
@EnableAutoConfiguration
@EnableTransactionManagement
@SpringBootApplication
@EnableJpaRepositories
public class ScanDataApp
{
public static void main( String[] args )
{
SpringApplication.run(ScanDataApp.class, args);//这里如果只是想看能否正常启动,run方法里可以为空,此处因为程序引用定时任务类。
}
}
此时运行程序就可以看到项目正常运行。如果是web项目需导入 springboot的web依赖的jar包,
一、配置application.peoperties文件
目录结构:application.properties代码:
这里贴上我项目的配置文件,配置springboot,配置数据库,配置redist,配置kafka
# ======================= spring boot configuration =============== server.port=8589 spring.aop.auto=true spring.aop.proxy-target-class=true server.session.timeout=18000 spring.velocity.check-template-location=false spring.velocity.enabled=false spring.resources.add-mappings=false spring.mvc.favicon.enabled=false spring.jmx.enabled=false multipart.enabled=false multipart.max-file-size=10MB # ======================= database configuration ================== spring.datasource.url=jdbc:mysql://59.110.42.200:3306/yccall?useUnicode=true&characterEncoding=utf8&autoReconnect=true&rewriteBatchedStatements=TRUE&useSSL=false spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.datasource.username=root spring.datasource.password=wdupec spring.datasource.max-active=5 spring.datasource.maximum-pool-size=10 spring.datasource.initial-size=1 spring.jpa.database=MySQL spring.jpa.show-sql=true spring.jpa.generate-ddl=true spring.jpa.hibernate.ddl-auto=update spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy # ======================= redis configuration ===================== spring.redis.host=192.168.10.8 spring.redis.password= spring.redis.port=6379 spring.redis.pool.max-idle=200 spring.redis.pool.min-idle=10 spring.redis.pool.max-active=8 spring.redis.pool.max-wait=-1 spring.redis.pool.max-total=5000 spring.redis.timeout= 2000 spring.redis.topic=scan.data.call.center.redis spring.redis.consumer.num=20 ## ============================ kefu kafka (not the one used for connector)============== youzai.kafka.producer.enabled=true youzai.kafka.producer.properties.bootstrap.servers=192.168.10.4:9092 youzai.kafka.consumer.enabled=true youzai.kafka.consumer.properties.zookeeper.connect=192.168.10.4:2181 youzai.kafka.consumer.properties.group.id=youzai.scan.data youzai.kafka.consumer.properties.client.id=${youzai.kafka.consumer.properties.group.id}-client-${random.int} youzai.kafka.consumer.properties.bootstrap.servers=${youzai.kafka.producer.properties.bootstrap.servers} youzai.kafka.bridge=true youzai.kafka.topic=scan.data.call.center youzai.kafka.consumer.properties.zookeeper.session.timeout.ms =60000 ## ============================ scan data data ============== youzai.kafka.redis.topic=scan.data.call.center.redis ## ============================ kefu kafka (not the one used for connector)============== youzai.scan.data.limit=100
二、写一个项目的启动类
注意@enablescheduling 是定时任务,没有定时任务可以把此注解去掉
@EnableAutoConfiguration注释,此注释自动载入应用程序所需的所有Bean——这依赖于Spring Boot在类路径中的查找。
@EnableTransactionManagement注释,它能够声明事务管理
@SpringBootApplication注解,它包括三个注解:
@Configuration:表示将该类作用springboot配置文件类。
@EnableAutoConfiguration:表示程序启动时,自动加载springboot默认的配置。
@ComponentScan:表示程序启动是,自动扫描当前包及子包下所有类。
@EnableJpaRepositories注解用于Srping JPA的代码配置 本项目操作数据访的方式是利用JPA的方式操作
代码:package org.uz.dxt;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@EnableScheduling
@EnableAutoConfiguration
@EnableTransactionManagement
@SpringBootApplication
@EnableJpaRepositories
public class ScanDataApp
{
public static void main( String[] args )
{
SpringApplication.run(ScanDataApp.class, args);//这里如果只是想看能否正常启动,run方法里可以为空,此处因为程序引用定时任务类。
}
}
此时运行程序就可以看到项目正常运行。如果是web项目需导入 springboot的web依赖的jar包,
相关文章推荐
- 从零一起学Spring Boot之LayIM项目长成记(三) 数据库的简单设计和JPA的简单使用。
- 使用Gradle创建一个最简单的Spring Boot项目
- 三、springboot项目的简单使用之:JPA使用操作数据库
- 1.2 使用IntelliJ IDEA搭建Spring-Boot与MongoDB数据的简单登录项目
- 二、springboot项目的简单使用之:定时任务
- 使用Spring Boot和Gradle创建AngularJS项目
- 【SpringBoot教程二】:RESTfull API简单项目的快速搭建
- 使用SpringBoot,优质快速开发Java项目
- 《Gradle教程系列》四.使用gradle搭建SpringBoot项目
- SpringBoot+SpringData实现SpringMVC简单项目
- 使用Spring MVC 、Spring、 Mybatis搭建一个简单的项目
- SpringBoot+Freemarker 项目ftl中使用include的异常
- 如何在Spring Boot项目使用参数校验
- 使用Dockerfile构建Springboot项目(视频)
- 使用IDEA从零配置springboot项目环境
- Maven构建一个最简单的Spring Boot + Spring MVC项目
- [转] 使用Spring Boot和Gradle创建项目
- 使用spring boot 改造老项目,多个数据源问题