xml文件中properties飘红报错

出现这个问题,先检查是不是重复使用了properties标签,就是看看是不是有好几组properties标签,或者出现了同一标签的嵌套问题。

1.检查 Maven 环境是否正常

首先需要检查 Maven 环境是否正确配置,可以通过在终端执行 "mvn -v" 命令来检查 Maven 版本信息。如果出现错误信息,则需要重新配置 Maven 环境。

2.检查 pom.xml 文件

在 pom.xml 文件中,需要确保 properties 标签的格式正确,通常应该在项目的顶层标签 project 中添加 properties 标签。例如:

<project>
    ...
    <properties>
        <spring.version>5.2.0.RELEASE</spring.version>
        <mybatis.version>3.4.6</mybatis.version>
    </properties>
    ...
</project>

需要注意的是,properties 标签中的变量名需要按照规范进行命名,通常使用小写字母和连字符。例如:spring.version。

3.检查命名空间

如果在 properties 标签中使用了命名空间,则需要确保正确引入命名空间。例如:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
          https://maven.apache.org/xsd/maven-4.0.0.xsd">

    <properties xmlns="http://www.springframework.org/schema/beans">
        <spring.version>5.2.0.RELEASE</spring.version>
        <mybatis.version>3.4.6</mybatis.version>
    </properties>
    
    ...
    
</project>

需要注意的是,如果使用了命名空间,则需要确保命名空间的 URL 与 XML 文件中引入的 URL 相同。

4.重新加载 Maven 依赖

最后,如果上述步骤都没有解决问题,可以尝试重新加载 Maven 依赖。可以在终端中进入项目根目录,并执行以下命令:

mvn clean install

该命令将重新加载 Maven 依赖,并重新编译项目。

还有一种可能是,你在pom.xml文件中定义了一个不存在的属性名,导致properties标签飘红报错。这时你需要检查一下你定义的属性名是否正确,并确认是否在其他地方使用了该属性名。
此外,如果你的pom.xml文件中引入了其他的依赖,但是这些依赖所需要的属性并没有在你的properties标签中定义,也会导致properties标签飘红报错。这时你需要查找相关依赖的文档或者官方网站,确认所需属性的名称和取值,并添加到你的properties标签中。
最后,如果你的pom.xml文件中使用了外部的properties文件,而这个文件的路径或者内容有误,也会导致properties标签飘红报错。这时你需要检查一下properties文件的路径和内容是否正确,并确保该文件能够被正确加载。
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
适合初学 springboot 的同学 --------------------------- maven配置:pom.xml --------------------------- <?xml version="1.0"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.4.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>demo</artifactId> <version>0.0.1-SNAPSHOT</version> <name>demo</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> --------------------------- src/main/resources/application.yml --------------------------- spring: # 指定静态资源的路径 resources: static-locations: classpath:/static/,classpath:/views/ thymeleaf: prefix: classpath:/templates/ server: port:8080 context-path:"/" --------------------------- DemoApplication 运行 main 方法即可启动 springboot --------------------------- package com.example.demo; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @ComponentScan(basePackages = {"com.example.*"}) //指定扫描包路径 public class DemoApplication { public static void main(String[] args) { SpringApplication.run(DemoApplication.class, args); } } --------------------------- HelloWorldController --------------------------- package com.example.controller; import java.util.HashMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; // @RestController返回的是json @RestController public class HelloWorldController { // http://localhost:8080/hello 返回的是文本"Hello World" @RequestMapping("/hello") public String index() { return "Hello World"; } /** * 本地访问内容地址 :http://localhost:8080/hello3 ;返回的是文本 */ @RequestMapping("/hello3") public String helloHtml(HashMap<String, Object> map) { map.put("hello", "欢迎进入HTML页面"); return "/index"; } } --------------------------- HelloWorldController --------------------------- package com.example.controller; import java.util.HashMap; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class SpringBootController { /** * 本地访问内容地址 :http://localhost:8080/hello2 ; 可访问到 * src/main/resources/views/index.html */ @RequestMapping("/hello2") public String helloHtml(HashMap<String, Object> map) { // 传参数hello到html页面 map.put("hello", "欢迎进入HTML页面"); return "/index"; } } --------------------------- src/main/resources/views/index.html --------------------------- <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> aaaaaaaaaaaaaaaaaaaaaaacccccccccccccc <p th:text="${hello}">dddd</p> </body> </html> --------------------------- 直接访问静态页面 --------------------------- http://localhost:8080/index.html 可直接访问到 src/main/resources/templates/index.html

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值