问答详情
源自:8-2 整合MyBatis - 实现基于mybatis的CRUD功能

写完saveUser 方法后启动工程报错

Failed to parse configuration class [com.springboot.SpringbooteApplication]; nested exception is java.io.FileNotFoundException: class path resource [resource.properties] cannot be opened because it does not exist

https://img.mukewang.com/5b02a3ab0001c89970971880.jpg


提问者:一枚加班的程序猿 2018-05-21 18:47

个回答

  • 草鱼禾
    2018-06-14 17:52:46

    工程路径建议不要中文

  • 一枚加班的程序猿
    2018-06-05 17:27:27

    @PropertySource(value="classpath:resource.properties")

    https://img1.mukewang.com/5b1656b000014f6603270800.jpg

    工程结构如图,注释

    package com.springboot.pojo;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.context.annotation.Configuration;import org.springframework.context.annotation.PropertySource;//读配置文件中内容一定要先maven编译一遍!!!!!!//.properties配置文件映射类//@Configuration 表示引用资源文件@Configuration//配置文件前缀@ConfigurationProperties(prefix="com.springboot.opensource")//resource.properties 文件路径@PropertySource(value="classpath:resource.properties")public class Resource {	private String name;	private String website;	private String language;		public String getName() {		return name;	}	public void setName(String name) {		this.name = name;	}	public String getWebsite() {		return website;	}	public void setWebsite(String website) {		this.website = website;	}	public String getLanguage() {		return language;	}	public void setLanguage(String language) {		this.language = language;	}}


  • 一枚加班的程序猿
    2018-06-05 16:55:12

    https://img3.mukewang.com/5b164fb80001a9ed70971880.jpg

    Failed to parse configuration class [com.springboot.SpringbooteApplication]; nested exception is java.io.FileNotFoundException: class path resource [resource.properties] cannot be opened because it does not exist


    是哪个文件写错了

  • 草鱼禾
    2018-05-22 20:31:48

    resource.properties这个文件存在吗?