Java常用配置文件总结

常用配置文件

mybatis.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?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>

<settings>
<!-- 开启二级缓存-->
<setting name="cacheEnabled" value="true"/>
</settings>

<environments default="development">
<environment id="development">
<!-- 配置mysql事务处理 -->
<transactionManager type="JDBC" />
<!-- 配置数据库连接信息 并启用Mybatis的连接池-->
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/数据库名字" />
<property name="username" value="root" />
<property name="password" value="123456" />
</dataSource>
</environment>
</environments>

<mappers>
<!-- 配置选择以xml文件的方式使用mybatis -->
<!-- <mapper resource="com/mapping/UserMapper.xml"/> -->
<!-- 以注解的方式来使用MyBatis 把所有的接口都在这里声明 -->
<mapper class="com.dao.UserMapper"/>
</mappers>
</configuration>

spring.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">

<!--
项目选用注解来标识bean对象,因此需要配置spring框架扫描注解的包路径
-->
<context:component-scan base-package="com.dao"></context:component-scan>
<context:component-scan base-package="com.service"></context:component-scan>
<context:component-scan base-package="com.web.controller"></context:component-scan>

<!--
告知spring数据库jdbc.properties的位置
-->
<context:property-placeholder location="classpath:jdbc.properties"/>

<!--
配置数据库连接用的连接池信息 选用dbcp连接池
-->
<bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driver}"></property>
<property name="url" value="${jdbc.url}"></property>
<property name="username" value="${jdbc.username}"></property>
<property name="password" value="${jdbc.password}"></property>
<property name="initialSize" value="${jdbc.initialSize}"></property>
<property name="maxActive" value="${jdbc.maxActive}"></property>
</bean>

<!-- 加上spring jdbctemplate的配置项 -->
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSource"></property>
</bean>

</beans>

log4j.properties

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#将等级为DEBUG的日志信息输出到console和file这两个目的地,console和file的定义在下面的代码
log4j.rootLogger=DEBUG,console,file

#控制台输出的相关设置
log4j.appender.console = org.apache.log4j.ConsoleAppender
log4j.appender.console.Target = System.out
log4j.appender.console.Threshold=DEBUG
log4j.appender.console.layout = org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=【%c】-%m%n

#文件输出的相关设置
log4j.appender.file = org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./log/zty.log
log4j.appender.file.MaxFileSize=10mb
log4j.appender.file.Threshold=DEBUG
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=[%p][%d{yy-MM-dd}][%c]%m%n

#日志输出级别
log4j.logger.org.mybatis=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG

db.properties

1
2
3
4
5
6
7
8
9
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.jdbcUrl=jdbc\:mysql\://localhost\:3306/luasedu2?characterEncoding=utf8
jdbc.user=root
jdbc.password=root
jdbc.initialPoolSize=10
jdbc.maxPoolSize=100
jdbc.minPoolSize=10
jdbc.acquireIncrement=10

Mapper.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zty.mapper.UserMapper">

<select id="selectUser" resultType="User">
select * from user_fo
</select>


<select id="queryUserById" resultType="User">
select * from user_fo where id = #{id}
</select>

<delete id="delete" parameterType="int">
delete from user_fo where id = #{id}
</delete>

</mapper>

Maven镜像配置文件

1
2
3
4
5
6
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

Thymeleaf

1
2
3
4
5
6
7
8
9
<!--        thymeleaf模板-->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
1
2
thymeleaf命名空间
xmlns:th="http://www.thymeleaf.org

web.xml

1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"
metadata-complete="true">

</web-app>

pom.xml资源过滤

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<!--在build中配置resuorces,来防止我们的资源导出失败-->
<build>
<resources>
<resource>
<directory>src/main/resources/</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource> </resources>
</build>

Java常用配置文件总结
https://zty-f.github.io/2022/05/03/Java常用配置文件总结/
作者
ZTY
发布于
2022年5月3日
更新于
2025年1月2日
许可协议