您好,欢迎来到纷纭教育。
搜索
您的当前位置:首页java项目框架依赖及一些配置文件

java项目框架依赖及一些配置文件

来源:纷纭教育

1.SpringBoot

 <!--添加当前项目的依赖启动器-->
    <dependencies>
        <!-- 1.依赖方式:添加SpringBoot启动器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>2.1.10.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <!-- 2.添加SpringMVC启动器依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.1.10.RELEASE</version>
        </dependency>
        <!-- 3.添加Mybatis 的启动器依赖-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.1</version>
        </dependency>
        <!--4. 添加thymeleaf  的依赖-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
            <version>2.1.10.RELEASE</version>
        </dependency>
        <!-- 5.添加mysql数据库的驱动包依赖-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.33</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.34</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

    <!--2、添加当前项目所依赖的插件-->
    <build>
        <!--添加tomcat的插件-->
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                    <port>8080</port>
                    <path>/</path>
                </configuration>
            </plugin>
        </plugins>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
            <!--资源拷贝插件-->
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.yml</include>
                    <include>**/*.html</include>
                    <include>**/*.js</include>
                    <include>**/*.css</include>
                    <include>**/*.png</include>
                    <include>**/*.jpg</include>
                    <include>**/*.properties</include>
                </includes>
            </resource>
        </resources>
    </build>

2.微服务

1.bootstrap.yml

nacos

spring:
  cloud:
    nacos:
      config:
        server-addr: 127.0.0.1:8848
      discovery:
        server-addr: 127.0.0.1:8848
    inetutils:
      preferred-networks: 172.19

2.application-dev.yml

spring:
  servlet:
    multipart:
      enabled: true
      max-request-size: 2147483800
      max-file-size: 2147483800
  datasource:
    type: com.alibaba.druid.pool.DruidDataSource
    #MySQL配置
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.121.128:3306/client_base?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai
    username: root
    password: 123456
  redis:
    host: 150.158.81.59
    port: 2965
    password: cyy0116.
  rabbitmq:
    # 多个用逗号隔开
    addresses: 111.229.139.176
    password: guest
    username: guest
    connection-timeout: 5000
    listener:
      direct:
        #设置 确认模式:NONE 只要消费就会确认,MANUAL 是手动提交确认回复,AUTO 是在成语执行完成没有异常的情况下自动提交 ack。
        #提交确认后 队列就会删除 消息
        acknowledge-mode: MANUAL
mybatis-plus:
  mapper-locations: classpath:/mapper/**/*.xml
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
common:
  security:
    auth:
      isDev: true
    ignores:
      antPatterns: /**/allowAuth/**,/assets/**,/apidoc/**,/**apiIndex.html,/**/actuator/**,/favicon.ico
config:
  # 验证码开关 on/off
  approveOpen: 'on'
  buttonAuth: 'off'
#阿里云短信发送方式配置
message:
  sms:
    key: code
    templateCode: SMS_1234567
    signName: 质子科技
    messageTemplateCode: 123456
    ali:
      accessKeyID: 1234567
      accessKeySecret: 1234567

3..application.yml

server:
  port: 8100
  servlet:
    session:
      timeout: 1800
spring:
  application:
    name: data
  sleuth:
    opentracing:
      enabled: false
    sampler:
      probability: 100
  profiles:
    active: dev
  jackson:
    time-zone: GMT+8
apidoc:
  test: 'on'
  baseurl: /api/services
  login:
    url: http://localhost:8000/center/login
#请求处理的超时时间
alyapi:
  appcode: 4e2ad2d5cf457799922d28d9be0861
ribbon:
  ReadTimeout: 120000
  #请求连接的超时时间
  ConnectTimeout: 30000

3.Mybatis

1.SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
    <!--使用properties标签, :创建成员变量  2. 引入外部属性文件-->
    <properties resource="jdbc.properties"></properties>


    <!--类型命名,给mapper映射文件里,全局限定名设置别名-->
    <typeAliases>
        <package name="entry"/><!--类名首字母小写-->
    </typeAliases>



   <!-- 数据库连接环境-->
    <environments default="development">
        <environment id="development">
            <transactionManager type="JDBC"/>
            <dataSource type="POOLED">
                <!-- ${}相当于+;     #{}相当于?占位 -->
                <property name="driver" value="${mysql.driver}"/>
                <property name="url" value="${mysql.url}"/>
                <property name="username" value="${mysql.username}"/>
                <property name="password" value="${mysql.password}"/>
            </dataSource>
        </environment>
    </environments>

  <!--  加载mapper映射文件-->
    <mappers>
       <!-- <mapper resource="entry/DeptMapper.xml"/>-->

        <!--第一种加载方式
        <mapper class="mapper.DeptMapper"/>-->
        <package name="mapper"/>
    </mappers>
</configuration>

2.jdbc.properties

mysql.driver=com.mysql.cj.jdbc.Driver
mysql.url=jdbc:mysql://127.0.0.1:3308/bookmanager?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
mysql.username=root
mysql.password=

3.log4j.properties

# Global logging configuration
#\u5728\u5f00\u53d1\u73af\u5883\u4e0b\u65e5\u5fd7\u7ea7\u522b\u81\u8bbe\u7f6e\u6210DEBUG\uff0c\u751f\u4ea7\u73af\u5883\u8bbe\u7f6e\u6210info\u6216error
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

4.MabatisandSpring

1.applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.3.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
       <!--1.加载jdbc属性文件-->
       <context:property-placeholder location="classpath:jdbc.properties"/>
       <!--2.配置数据库环境-->
       <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
              <property name="driverClassName" value="${mysql.driver}"/>
              <property name="url" value="${mysql.url}"/>
              <property name="username" value="${mysql.username}"/>
              <property name="password" value="${mysql.password}"/>
       </bean>
     <!--  3.配置SqlSessionFactoryClass对象-->
       <bean id="factory" class="org.mybatis.spring.SqlSessionFactoryBean">
              <property name="dataSource" ref="dataSource"/>
              <property name="configLocation" value="classpath:SqlMapConfig.xml"/>
       </bean>
       <!--4.配置mapper映射文件扫描路径-->
       <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
              <property name="basePackage" value="com.mapper"/>
              <property name="sqlSessionFactoryBeanName" value="factory"/>
       </bean>
       <!--配置spring框架的注解扫描路径-->
       <context:component-scan base-package="com"/>

       <!--配置spring注解模式下,生成动态代理类-->
       <aop:aspectj-autoproxy/>
       <!--配置事务管理器对象  -->
       <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
              <property name="dataSource" ref="dataSource"/>
       </bean>
       <!--注解模式下,事务传播的配置-->
       <tx:annotation-driven transaction-manager="transactionManager"/>


</beans>

2.SqlMapConfig.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<!--设置别名,别名是类的首字母小写,别名用在mapper映射文件里-->
    <typeAliases>
         <package name="com.entry"/>
        <package name="com.pojo"/>
    </typeAliases>

</configuration>

 3.jdbc.properties

mysql.driver=com.mysql.cj.jdbc.Driver
mysql.url=jdbc:mysql://127.0.0.1:3308/bookmanager?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
mysql.username=root
mysql.password=

4.log4j.properties

# Global logging configuration
#\u5728\u5f00\u53d1\u73af\u5883\u4e0b\u65e5\u5fd7\u7ea7\u522b\u81\u8bbe\u7f6e\u6210DEBUG\uff0c\u751f\u4ea7\u73af\u5883\u8bbe\u7f6e\u6210info\u6216error
log4j.rootLogger=DEBUG, stdout
# Console output...
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

5.Springmvc

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"

       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-4.3.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context-4.3.xsd
       http://www.springframework.org/schema/tx
       http://www.springframework.org/schema/tx/spring-tx-4.3.xsd
       http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

       <!--1.配置处理器的映射器和适配器 采用SpringMVC的默认值-->
       <mvc:annotation-driven conversion-service="formatc"/>
       <!--配置控制器的注解扫描-->
       <context:component-scan base-package="com.controller"/>
       <!-- 配置 时间类型适配器 -->
       <bean id="formatc" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
              <property name="converters">
                     <list>
                            <bean class="com.util.DateConverter"/>
                     </list>
              </property>
       </bean>

       <!--配置-->
        <mvc:interceptors>
               <mvc:interceptor>
                      <mvc:mapping path="/login"/>
                      <bean class="com.interceptor.MyInterceptor"/>
               </mvc:interceptor>
        </mvc:interceptors>
</beans>

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- fenyunshixun.cn 版权所有 湘ICP备2023022495号-9

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务