个人填坑记录

目录

一、git提交问题

二、maven打包部署问题

三、mybatis的mapper的xml文件建立存放目录,及更新数据库数据锁定问题

四、spring配置文件头问题

五、maven命令安装jar包到本地仓,使pom.xml引入生效

六、IDEA中修改maven项目JDK版本

七、打包部署时类似mybatis报XML文件绑定异常

八、weblogic部署Java项目的包冲突问题

九、springmvc项目中实体属性带下划线对应关系

十、JAVA后台生成图片保存到项目目录中,JSP页面显示小贴士


一、git提交问题

如图红框中一定要填写提交说明信息,否则一时大意产生无法提交git仓库的乌龙。 

二、maven打包部署问题

clear 清空target文件,package打包时会执行@SpringBootTest标记类中的@Test方法。如果测试类中有数据变动之类的测试方法,产生意向不到的结果(比如测试修改数据库)。

项目中pom.xml文件配置如下:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>

        </plugins>
        <!--设置j生成jar包的名称-->
        <finalName>${project.artifactId}</finalName>
    </build>

改进方法:spring boot项目跳过测试,使用spring-boot-maven-plugin,需要在pom.xml里加: 

<properties>
   <skipTests>true</skipTests>
</properties>

三、mybatis的mapper的xml文件建立存放目录,及更新数据库数据锁定问题

1. 注意:在resources资源文件夹下创建com\mybatis_demo2\mapper目录,逐层单个建立,不能在idea中com.mybatis_demo2.mapper直接建立。然后从磁盘重新刷新加载项目。血泪史切记。

2. 更新oracle数据库表数据时,出现将此条数据锁定的情况,会导致应用不报错,但是又无法更新数据的情况。(原因是这条数据锁定后无法更新,导致一致执行而卡住)

四、spring配置文件头问题

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">

问题:运行程序无法找到http://www.springframework.org/schema/util/spring-util.xsd。

原因是缺少jar包未导入。导致无法找到spring-util.xsd且配置文件爆红。beans中的引入通常会先在本地搜索。而非直接网络寻址。

五、maven命令安装jar包到本地仓,使pom.xml引入生效

mvn install:install-file -Dfile=D:\newJar\si-facade.jar -DgroupId=com.wqbr -DartifactId=si-facade -Dversion=1.0 -Dpackaging=jar
注意:-Dfile路劲中不能有空格,执行目录无特定要求

参数说明:
-DgroupId:表示jar对应的groupId     
<groupId>io.confluent</groupId>

-DartifactId: 表示jar对应的artifactId
<artifactId>kafka-schema-registry-client</artifactId>

-Dversion: 表示jar对应的 version
<version>4.1.1</version>

六、IDEA中修改maven项目JDK版本

注意界面修改和pom.xml文件的修改

Settings面板

Project Structure面板

 

 pom.xml文件

七、打包部署时类似mybatis报XML文件绑定异常

原因是打的包中没有产生class文件外XML文件等。

在pom.xml文件中增加配置即可解决:

		<resources>
			<resource>
				<directory>src/main/java</directory>
				<includes>
					<include>**/*.xml</include>
				</includes>
				<filtering>true</filtering>
			</resource>
			<resource>
				<directory>src/main/resources</directory>
				<includes>
					<include>**/*.properties</include>
					<include>**/*.xml</include>
				</includes>
			</resource>
		</resources>

八、weblogic部署Java项目的包冲突问题

在更换项目java(jdk)环境,或容器weblogic环境时出现包冲突报错问题。

报错:

Caused by: java.lang.LinkageError: loader constraint violation: when resolving field "NODE" the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) of the referring class, javax/xml/xpath/XPathConstants, and the class loader (instance of <bootloader>) for the field's resolved type, javax/xml/namespace/QName, have different Class objects for that type

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'personInsuranceMapper' defined in URL [zip:D:/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/gzrssi_war/b6v2hv/war/WEB-INF/lib/_wl_cls_gen.jar!/com/wqbr/gzrssi/personInsurance/persistence/PersonInsuranceMapper.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [zip:D:/Oracle/Middleware/Oracle_Home/user_projects/domains/base_domain/servers/AdminServer/tmp/_WL_user/gzrssi_war/b6v2hv/war/WEB-INF/lib/_wl_cls_gen.jar!/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.LinkageError: loader constraint violation: when resolving field "NODE" the class loader (instance of weblogic/utils/classloaders/ChangeAwareClassLoader) of the referring class, javax/xml/xpath/XPathConstants, and the class loader (instance of <bootloader>) for the field's resolved type, javax/xml/namespace/QName, have different Class objects for that type

weblogic.application.ModuleException: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.wqbr.gzrssi.accident.persistence.AccidentMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

报错的大概意思:项目启动的时候加载了一个javax/xml/namespace/QName类,而本身java环境中已经有javax/xml/namespace/QName类,发生冲突。

解决方法:在项目的weblogic.xml 文件中有<wls:prefer-web-inf-classes>true</wls:prefer-web-inf-classes>配置,设置为false可以解决。

weblogic.xml 这个配置文件的<prefer-web-inf-classes>true</prefer-web-inf-classes> 配置是只先加载项目里的class文件,再加载weblogic的class,也就是因为这个配置导致项目里maven引入jar文件下有 javax/xml/namespace/QName.class,jdk / weblogic的某个jar文件下也有 javax/xml/namespace/QName.class却没有加载到,但是后者才是程序所需要的。

总结:在weblogic中部署Java应用时,常遇到包冲突问题时,可以通过修改weblogic.xml配置解决,另通过jfind.jar 找出冲突的class所在的包,删除冲突包也可以解决。

还有时候可能报错找不到某个class文件,除class文件冲突还有可能先后加载的顺序问题,导致项目中真正需要的class文件却没有被加载进来。

九、springmvc项目中实体属性带下划线对应关系

下划线连接的字段属性 与 mybatis查询语句的字段一致带下划线,页面 与 实体bean类一致带下划线。(注:数据库使用的oracle 12C,持久框架mybatis)

十、JAVA后台生成图片保存到项目目录中,JSP页面显示小贴士

页面代码:

后台代码:

url 的获取方式:

在classes 类路径中:

        //获取到项目的 classes 目录路径
        String url = this.getClass().getClassLoader().getResource("").getPath();

 在项目目录中,根目录:

        // 获取项目目录路径(即:wqdemotwo_war的路径)
        String url=projectPathService.getProjectPath();

ProjectPathService类,getProjectPath()方法的事项代码:

package com.wqbr.wqdemotwo.service.impl;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;

/**
 * 获取项目目录路径
 * @author lv
 * @date 2024年3月12日
 */
@Service
@Lazy(false)
public class ProjectPathService implements ServletContextAware {

    private ServletContext servletContext;

    @Override
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    public String getProjectPath() {
        return servletContext.getRealPath("/");
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值