遇到的一些问题

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();
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值