zoukankan      html  css  js  c++  java
  • -- 记录 -- 问题记录

    thymeleaf不能渲染问题

    发现叶子模板的文件根本没有被渲染就直接输出到流量器

    如果渲染过后的话应该是不会显示红框内容的
    发现原因:
    没有将html放置templates中。

    在springboot中其他静态文件路径是不会被thymeleaf渲染的,只有放置指定的路径

    从spring boot配置文件中读取一个Map结构数据

    配置文件
    map.properties

    com.hjh.map[status]=123
    com.hjh.map[message]=xxx
    

    map实例

    MyMap.java

    @Component
    @ConfigurationProperties(prefix = "com.hjh")
    @PropertySource("classpath:map.properties")
    public class MyMap {
    
        public Map<String, String> map;
    
        public Map<String, String> getMap() {
            return map;
        }
    
        public void setMap(Map<String, String> map) {
            this.map = map;
        }
    }
    

    提供getset

    这样就可以使用@Autowrite获得map了

    springboot包的命名引发的问题。

    SpringBoot项目的Bean装配默认规则是根据项目入口文件(Application)类所在的包位置从上往下扫描! 
    例如。Application类所在包为com.hjh。则只会扫描com.hjh包和其子包。

    可以使用@ComponentScan指定要扫描的包以及要扫描的类。

    场景一

    springboot中无法注入Bean

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'xxx: Unsatisfied dependency expressed through field 'xxx': No qualifying bean of type [xxx] found for dependency [xxx]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [xxx] found for dependency [com.example.repositories.UserRepository]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    

    原因:
    注入bean的类跳出了项目入口文件(Application)的包范围,没有被扫描到。

    场景二

    在springboot多模块下。项目运行模块,无法获得某个模块的配置,或者Bean。

    也可能是入口文件和其他项目的包名问题。
    要确保要注入的对象有被扫描到、

  • 相关阅读:
    struts2的在aJax中无法传参数到后台使用:解决方法
    jqGrid的属性(2)特指内容属性
    [leetcode]Binary Tree Maximum Path Sum
    判断二叉树是否平衡(Bottomup)
    [转]反向迭代器(rbegin,rend)
    Crack Interview 3.3
    Crack Interview 9.1 合并排序数组
    字符串转整数
    [转]了解如何通过reverse_iterator的base得到iterator
    通过bitmap的方式用8个int实现对256个char是否出现过做记录
  • 原文地址:https://www.cnblogs.com/hjh614/p/11376662.html
Copyright © 2011-2022 走看看