一、springboot项目的简单使用
来源:互联网 发布:职场女性知乎 编辑:程序博客网 时间:2024/06/05 17:06
接着上篇搭建好项目之后,开始使用项目
一、配置application.peoperties文件
目录结构:
application.properties代码:
这里贴上我项目的配置文件,配置springboot,配置数据库,配置redist,配置kafka
# ======================= spring boot configuration ===============server.port=8589spring.aop.auto=truespring.aop.proxy-target-class=trueserver.session.timeout=18000spring.velocity.check-template-location=falsespring.velocity.enabled=falsespring.resources.add-mappings=falsespring.mvc.favicon.enabled=falsespring.jmx.enabled=falsemultipart.enabled=falsemultipart.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=falsespring.datasource.driver-class-name=com.mysql.jdbc.Driverspring.datasource.username=rootspring.datasource.password=wdupecspring.datasource.max-active=5spring.datasource.maximum-pool-size=10spring.datasource.initial-size=1spring.jpa.database=MySQLspring.jpa.show-sql=truespring.jpa.generate-ddl=truespring.jpa.hibernate.ddl-auto=updatespring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy# ======================= redis configuration =====================spring.redis.host=192.168.10.8spring.redis.password=spring.redis.port=6379spring.redis.pool.max-idle=200spring.redis.pool.min-idle=10spring.redis.pool.max-active=8spring.redis.pool.max-wait=-1spring.redis.pool.max-total=5000spring.redis.timeout= 2000spring.redis.topic=scan.data.call.center.redisspring.redis.consumer.num=20## ============================ kefu kafka (not the one used for connector)==============youzai.kafka.producer.enabled=trueyouzai.kafka.producer.properties.bootstrap.servers=192.168.10.4:9092youzai.kafka.consumer.enabled=trueyouzai.kafka.consumer.properties.zookeeper.connect=192.168.10.4:2181youzai.kafka.consumer.properties.group.id=youzai.scan.datayouzai.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=trueyouzai.kafka.topic=scan.data.call.centeryouzai.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@EnableJpaRepositoriespublic class ScanDataApp{ public static void main( String[] args ) { SpringApplication.run(ScanDataApp.class, args);//这里如果只是想看能否正常启动,run方法里可以为空,此处因为程序引用定时任务类。 }}
此时运行程序就可以看到项目正常运行。如果是web项目需导入 springboot的web依赖的jar包,
阅读全文
0 0
- 一、springboot项目的简单使用
- springboot的使用一
- 简单的springboot项目搭建
- 一个简单的Springboot项目
- 二、springboot项目的简单使用之:定时任务
- SpringBoot 学习记录(一): 简单web项目
- springboot+javamail的简单使用
- 简单的springboot使用freemarker
- SpringBoot——创建一个简单的SpringBoot项目
- 一起学习springboot[一,简单的springboot工程搭建]
- 一个简单的SpringBoot整合Mybatis项目
- 快速搭建一个简单的springboot项目
- spring cloud-学习之路(一):搭建一个简单的Springboot项目
- Spring Boot 入门 (一)——建一个最简单的springboot项目
- 三、springboot项目的简单使用之:JPA使用操作数据库
- SpringBoot项目简单建立
- Springboot+jedis简单项目
- SpringBoot简单入门(一)
- Stack Overflow 的2017全球开发者调查(程序猿必看干货)
- gulp压缩文件(未完)
- c++中的C
- Linux下安装软件的几种方法
- aidl传递boolean数据byte数组
- 一、springboot项目的简单使用
- 7、模糊
- MFC 分页bar
- HDU--1005--Number Sequence
- 如何解决启动Error:com.intellij.util.indexing.StorageException问题?
- python 安装Pillow
- LocalStorage基础知识小结
- linux的动态库和静态库
- C语言创建单链表