JAVA学习过程中遇到的问题

前言

记录学习过程中遇见的各种问题。希望对你有帮助。

目录

前言

1、新建maven项目时,archetype项目骨架加载慢

 2、maven的pop.xml添加依赖项无法检测到

3、java: 无效的目标发行版: 20

4、idea添加maven依赖太慢

5、CTRL+C+V复制粘贴太慢

6、Swagger写接口文档,无法打开localhost:8080/swagger-ui.html

7、java.io.IOException: Could not find resource src/main/resources/config.properties

8、java: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

 9、MyBatis找不到名为java.pojo.Student.findAll的映射语句。

10、slf4j

11、配置仓库

12、端口占用

13、服务器异常

14、无法解析插件 org.springframework.boot:spring-boot-maven-plugin:2.6.4

15、非法反射

16、方法未从其超类重写方法(springmvc拦截器)


1、新建maven项目时,archetype项目骨架加载慢

解决:

1、将archetype-catalog.xml放在maven本地仓库

 2、指定虚拟机选项为-DarchetypeCatalog为internal

 3、setting.xml加入阿里云镜像

在maven的配置文件(maven.config.setting.xml)中加入下面代码(阿里云镜像)

<mirrors>
        <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>*</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>;
        </mirror>
    </mirrors>

 2、maven的pop.xml添加依赖项无法检测到

进行maven分模块练习时,将实体类domain移动至其他模块,需要添加别的模块的依赖。

  • 无法解析 com.itheima:maven_03_pojo:1.0-SNAPSHOT

解决:

初始模块时会出现

<groupId>org.example</groupId>
<artifactId>maven_03_pojo</artifactId>
<version>1.0-SNAPSHOT</version>

将其改为

<groupId>com.itheima</groupId>
<artifactId>maven_03_pojo</artifactId>
<version>1.0-SNAPSHOT</version>

3、java: 无效的目标发行版: 20

解决:改目标字节码(SDK与JAVA版本不一致导致)(编译器问题)

4、idea添加maven依赖太慢

使用阿里云的仓库:
在maven的settings.xml 配置文件里添加mirrors的子节点。 


<mirror>

<id>nexus-aliyun</id>

<mirrorOf>*</mirrorOf>

<name>Nexus aliyun</name>

<url>http://maven.aliyun.com/nexus/content/groups/public</url>

</mirror>

将默认的maven修改为本地的maven就好了。(修改Maven主路径)


 

在settings.xml中加入

<mirrors>
    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
        <mirrorOf>central</mirrorOf>
    </mirror>
</mirrors>

5、CTRL+C+V复制粘贴太慢

6、Swagger写接口文档,无法打开localhost:8080/swagger-ui.html

解决:

springboot版本改为2.6.4(原版本2.0.3.RELEASE)

swagger版本改为2.9.2

配置类修改为

@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig implements WebMvcConfigurer {
    @Bean
    public Docket getDocket() {
        ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder();
        apiInfoBuilder.title("Swagger2 在线接口文档");
        apiInfoBuilder.description("Swagger2 在线接口文档");
        apiInfoBuilder.version("1.0.0");
        apiInfoBuilder.contact(new Contact("itcodai", "", ""))
                .build();
        ApiInfo apiInfo = apiInfoBuilder.build();

        Docket docket = new Docket(DocumentationType.SWAGGER_2);
        docket.apiInfo(apiInfo);
        docket.select()
                .apis(RequestHandlerSelectors.basePackage("com.itcodai.course01.controller"))
                .paths(PathSelectors.any())
                .build();
        return docket;
    }
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}

7、java.io.IOException: Could not find resource src/main/resources/config.properties

问题:

找不到文件 

解决:

在项目结构中将包设为资源 

8、java: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'

问题:

由于Lombok 版本兼容性的问题导致

解决:

JDK21情况下

1、将pom.xml中Lombok对应的代码替换成下面的即可解决

<dependency>
 <groupId>org.projectlombok</groupId>
 <artifactId>lombok</artifactId>
 <version>1.18.30</version>
</dependency>

 2、修改项目结构中的SDK

 9、MyBatis找不到名为java.pojo.Student.findAll的映射语句。

 问题:

文件名错误

解决:

对于StudentMapper.xml中

 注意命名空间namespace

<mapper namespace="pojo.StudentMapper">
    <select id="findAll" resultType="pojo.Student">
        select * from student
    </select>

    <insert id="insert" parameterType="pojo.Student">
        insert into student(name,gender,age,score) values(#{name},#{gender},#{age},#{score})
    </insert>

    <delete id="delete" parameterType="int">
        delete from student where id=#{id}
    </delete>

    <update id="update" parameterType="pojo.Student">
        update student set name=#{name},gender=#{gender},age=#{age},score=#{score} where id=#{id}
    </update>

</mapper>

List<Student> student = sqlSession.selectList("pojo.Student.findAll");

改为

 List<Student> student = sqlSession.selectList("pojo.StudentMapper.findAll");

10、slf4j

问题:这意味着你的应用程序尝试使用SLF4J日志框架,但找不到合适的绑定实现。SLF4J提供了一个接口,允许你选择底层的日志实现,如logback、log4j等。

解决:添加这个依赖

<dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-simple</artifactId>
      <version>1.7.25</version>
      <scope>compile</scope>
    </dependency>

11、配置仓库

<!-- 配置仓库 -->
    <repositories>
        <repository>
            <id>central</id>
            <url>http://host:port/content/groups/public</url>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>central</id>
            <url>http://host:port/content/groups/public</url>
        </pluginRepository>
    </pluginRepositories>

12、端口占用

Windows下如何查看某个端口被谁占用 | 菜鸟教程 (runoob.com)

13、服务器异常

14、无法解析插件 org.springframework.boot:spring-boot-maven-plugin:2.6.4

spring-boot的版本不对

如果把2.0.3.RELEASE改成2.6.4则出现错误

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.3.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

15、非法反射

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.baomidou.mybatisplus.core.toolkit.SetAccessibleAction (file:/C:/Users/lovertx/.m2/repository/com/baomidou/mybatis-plus-core/3.4.3/mybatis-plus-core-3.4.3.jar) to field java.lang.invoke.SerializedLambda.capturingClass
WARNING: Please consider reporting this to the maintainers of com.baomidou.mybatisplus.core.toolkit.SetAccessibleAction
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

解决:

在此文件中

将虚拟机IP地址改成自己的。 

并将这个文件中

将active: dev改成active: local

16、方法未从其超类重写方法(springmvc拦截器)

 

原因:导的包不对

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

将其修改为

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.servlet.HandlerInterceptor;
  • 25
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值