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。

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

  • 相关阅读:
    Oracle 学习笔记 12 -- 序列、索引、同义词
    解决:设置中打开蓝牙,測试机不会自己主动搜索设备
    mysql 数据库查询最后两条数据
    jQuery中this与$(this)的差别
    Apache http server linux 安装过程说明
    Swift学习——Swift基础具体解释(一)
    CloudFoundry V2 单机版离线安装(伪离线安装)
    CF1119F Niyaz and Small Degrees
    2019-8-31-C#-如何引用-WshShell-类
    2019-8-31-C#-如何引用-WshShell-类
  • 原文地址:https://www.cnblogs.com/hjh614/p/11376662.html
Copyright © 2011-2022 走看看