首页 > 编程语言 >Java Web技术栈

Java Web技术栈

时间:2022-09-02 04:22:07浏览次数:59  
标签:Web Java spring boot 技术 new props put org

SpringBoot

Maven
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.create</groupId>
    <artifactId>Springboot</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>Springboot</name>
    <description>Springboot</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>


Java代码
package com.create.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SpringbootApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootApplication.class, args);
    }

}

SpringBoot Web

maven for java web
 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
 </dependency>

JavaWeb 前端开发模板

maven
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
或
<dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
        <groupId>org.thymeleaf.extras</groupId>
        <artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>

数据库================

Druid数据池

Maven And Yml
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid</artifactId>
    <version>1.2.8</version>
</dependency>

Yml------------
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/finally_work?serverTimezone=UTC&useUnicode=true&characterEncodeing=utf-8&useSSL=false
    password: "000000"
    username: root
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource

    initialSize: 5
    minIdle: 5
    maxActive: 20
    maxWait: 60000
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
    #   配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
    filters: stat,wall,log4j
    maxPoolPreparedStatementPerConnectionSize: 20
    useGlobalDataSourceStat: true
    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher
Druid Confige For Java
@Configuration
public class DruidConfig {
    //加载application.yaml中的Druid配置
    @ConfigurationProperties(prefix = "spring.datasource")
    @Bean
    public DataSource druid(){
        return  new DruidDataSource();
    }

    //配置Druid的监控
    //1、配置一个管理后台的Servlet
    @Bean
    public ServletRegistrationBean statViewServlet(){
        ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
        Map<String,String> initParams = new HashMap<>();

        initParams.put("loginUsername","root");
        initParams.put("loginPassword","123456");
        initParams.put("allow","");//默认就是允许所有访问
        initParams.put("deny","192.168.15.21");

        bean.setInitParameters(initParams);
        return bean;
    }

    //2、配置一个web监控的filter
    @Bean
    public FilterRegistrationBean webStatFilter(){
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(new WebStatFilter());

        Map<String,String> initParams = new HashMap<>();
        initParams.put("exclusions","*.js,*.css,/druid/*");

        bean.setInitParameters(initParams);

        bean.setUrlPatterns(Arrays.asList("/*"));

        return  bean;
    }
}

}

Mybatis

Maven And Yml
maven-----------
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
</dependency>
yml-------------
spring:
    datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        password: "000000"
        username: root
        url: jdbc:mysql://localhost:3306/finally_work?serverTimezone=UTC&useUnicode=true&characterEncodeing=utf-8&useSSL=false

MybatisPlus

Maven
<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.2</version>
</dependency>

消息中间件================

Kafka

Maven
<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>1.0.2</version>
</dependency>
Java
    public void Product(){
        //生产发短信通知消息--->Kafka4
        System.out.println("生产发短信通知消息--->Kafka");
        Properties props = new Properties();
        props.put("bootstrap.servers", "192.168.100.10:9092");//连接的集群,broker-list。9092是其端口号
//        props.put("acks", "all");
//        props.put("retries", 1);//重试次数
//        props.put("batch.size", 5);//批次大小
//        props.put("linger.ms", 1);
//        props.put("buffer.memory", 10);//缓冲物大小
        props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
        props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

        Producer<String, String> producer = new KafkaProducer<String, String>(props);

        for(int i = 0; i < 20; i++)
            producer.send(new ProducerRecord<String, String>("consumer", Integer.toString(i), "test-" + Integer.toString(i)));
        producer.close();

        }


    public void ConSumer(){
        System.out.println("consumer------------------------");
        Properties props = new Properties();
        props.put("bootstrap.servers", "192.168.100.10:9092");
        props.put("group.id", "test");
        props.put("enable.auto.commit", "true");
        props.put("auto.commit.interval.ms", "1000");
        props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);
        consumer.subscribe(Arrays.asList("consumer"));
        while (true) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            for (ConsumerRecord<String, String> record : records)
                System.out.printf("offset = %d, key = %s, value = %s%n", record.offset(), record.key(), record.value());
        }
    }

测试工具================

Swager

Maven
<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.9.2</version>
</dependency>
<dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.9.2</version>
</dependency>
Java
@Configuration
@EnableSwagger2
public class swagger2Config {}

标签:Web,Java,spring,boot,技术,new,props,put,org
From: https://www.cnblogs.com/createhm/p/16642717.html

相关文章

  • 工作中如何做好技术积累
    本文转自:https://tech.meituan.com/2018/04/16/study-vs-work.html-----------------------------------------------------------------------引言古人云:“活到老,学到......
  • webpack中的插件
    1.webpack插件的作用通过安装和配置第三方插件,可以拓展webpack的能力,从而让webpack用起来更方便。最常用的webpack插件如下有两个:webpack-dev-server类似于node.js......
  • 2022 年 8 月 JavaScript 新闻和更新
    2022年8月JavaScript新闻和更新向所有JavaScript崇拜者致敬!很遗憾夏天结束了,但我们准备了一份最新的JavaScript新闻摘要来让你振作起来。今天,您将熟悉我们全新......
  • 什么是 Web 组件?我们更喜欢哪个 Web 组件库?
    什么是Web组件?我们更喜欢哪个Web组件库?WebComponents是一种结构,它允许我们创建可重用的自定义元素并在Web应用程序中使用它们。例如,我们有两个不同的项目,我们将......
  • java.beans.BeanInfo
    可用通过BeanInfo接口创建BeanInfo类,并提供关于bean的方法、属性、事件和其他特性的显式信息。通用方式BeanInfobeanInfo=Introspector.getBeanInfo(TradeTransaction......
  • [Java]零基础入门学习Day(1)
    Java环境的搭建Java开发工具Eclipse的下载与安装Java的第一个程序("HelloWorld") 一.Java环境的搭建1.下载JDK 首先我们需要下载java的开发工具包JDK,下载地址:......
  • Day 5 java
    Scanner的用法首先引用import库importjava.util.Scanner;下面输入时Scannerscanner=newScanner(System.in);Stringname=scanner.next();charAt(i)name.char......
  • Java-java基础知识
    JavaSEJava标准版JVM--Java虚拟机,一种软件平台JRE--Java运行环境JDK--Java开发工具包Java是平台独立的或跨平台的,不需要更改就可以在各平台运行bin中包含java重要......
  • WEB自动化-01-Cypress 介绍
    1.Cypress介绍1.1Cypress简介  Cypress是一款基于JavaScript的下一代前端测试工具。可以对浏览器中运行的任何内容进行快速、简单和可靠的测试。  Cypress......
  • java El表达式
    //支持:中文、英文、下划线,单独或三者合一:Stringregex="^[\\u4E00-\\u9FA5A-Za-z0-9_]+$";if("Adsf_最大的".matches(regex)){System.out.println(true);}//输......