Spring 框架中都用到了哪些设计模式?
- 代理模式—在AOP和remoting中被用的比较多。
- 单例模式—在spring配置文件中定义的bean默认为单例模式。
- 模板方法—用来解决代码重复的问题。比如. RestTemplate, JmsTemplate, JpaTemplate。
- 前端控制器—Spring提供了DispatcherServlet来对请求进行分发。
- 视图帮助(View Helper )—Spring提供了一系列的JSP标签,高效宏来辅助将分散的代码整合在视图里。
- 依赖注入—贯穿于BeanFactory / ApplicationContext接口的核心理念。
- 工厂模式—BeanFactory用来创建对象的实例。
c3p0数据库连接池死锁问题
WARNING: com.mchange.v2.async.ThreadPoolAsynchronousRunner$DeadlockDetector@4b9cafa7 -- APPARENT DEADLOCK!!! Complete Status:
Managed Threads: 3
Active Threads: 3
Active Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@19f67d43 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@599c706 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#1)
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@32d95dc9 (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0)
Pending Tasks:
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@5c9c5133
com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask@1a971ac5
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@365e8926
com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask@787e39ac
Pool thread stack traces:
Thread[com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#2,5,main]
java.lang.StringCoding.set(StringCoding.java:53)
java.lang.StringCoding.encode(StringCoding.java:270)
java.lang.String.getBytes(String.java:946)
使用环境,spring + hibernate +c3p0
暂时处理方法
<!--JDBC的标准参数,用以控制数据源内加载的PreparedStatements数量。但由于预缓存的statements
属于单个connection而不是整个连接池。所以设置这个参数需要考虑到多方面的因素。
如果maxStatements与maxStatementsPerConnection均为0,则缓存被关闭。Default: 0-->
<property name="maxStatements" value="0"/>
<!--连接池用完时客户调用getConnection()后等待获取连接的时间,单位:毫秒。超时后会抛出-->
<!--SQLEXCEPTION,如果设置0,则无限等待。Default:0-->
<property name="checkoutTimeout" value="100"/>
tomcat报错
警告 [main] org.apache.catalina.webresources.Cache.getResource
无法将位于[/WEB-INF/classes/templates/framework/help/helpinfo.html]的资源添加到Web应用程序[/zhfx]的缓存中,
因为在清除过期缓存条目后可用空间仍不足 - 请考虑增加缓存的最大空间。
解决办法:
在 /conf/context.xml 的 前添加以下内容(大小默认是1024,单位是KB):
< Resources cachingAllowed=“true” cacheMaxSize=“100000” />
springboot找不到配置文件
Spring Boot Configuration Annotation Processor not found in claspath
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
或者
@PropertySource("classpath:application.properties")
springboot 添加依赖报错
重新build项目
idea 项目目录后有0%classes,0% lines covered
ctrl+alt+F6或者
window安装zookeeper
启动zkServer或zKCli闪退,
pause可以查看错误信息
%java% 改成java
iterator.remove() 报错java.lang.UnsupportedOperationException
Arrays.asList()创建出来的大小是固定的,不能remove
List<Integer> list = new ArrayList<>(Arrays.asList(1,2,3));
Iterator<Integer> iterator = list.iterator();
for (;iterator.hasNext();){
Integer next = iterator.next();
if (next == 2){
iterator.remove();
}
}
for (Integer integer : list) {
System.out.println(integer);
}
连接数据库提示url找不到
com.mysql.cj.exceptions.WrongArgumentException: The database URL cannot be null.
配置问题:
将datasource.jdbc-url
改为datasource.url
使用DISTINCT关键字解决 联合查询出现重复数据
使用left join,
左右表 1:1 或 1:0,左表的所有记录都会显示,右表只显示符合条件的记录。
左右表 1:N ,记录数会多于左表的记录数
SELECT
DISTINCT p.*
, pc.collection_name
FROM
t_project p
LEFT JOIN t_project_collection pc ON p.project_collection = pc.id
LEFT JOIN t_project_member pm ON p.id = pm.project_id
WHERE
1 = 1
springboot使用docker部署无法访问静态文件
private String getConfigXml(String content) {
//config.xml在resources目录下
InputStream stream = this.getClass().getResourceAsStream("/config.xml");
Document doc = null;
//获取config.xml
try {
SAXReader reader = new SAXReader();
//创建并读取一个Document对象
doc = reader.read(stream);
//得到标签对象
Element contatcElem = doc.getRootElement();
Element definition = contatcElem.element("definition");
Element script = definition.element("script");
script.setText(content);
} catch (DocumentException e) {
logger.error("DocumentException : {}", e.getMessage());
e.printStackTrace();
}
return doc.asXML();
}