Spring中的@Lookup注解和<lookup-method>标签

本文介绍了Spring框架中用于实现方法注入的两种方式:@Lookup注解和<lookup-method/>标签。这两种方式允许在单例bean中获取非单例bean的新实例,避免了直接使用ApplicationContext导致的代码耦合。通过实例演示,解释了如何配置和使用这两个特性,展示了Spring如何利用CGLIB动态代理在运行时生成代理类以返回新的bean实例。最后,通过@Lookup注解的使用,展示了如何在不实现具体方法的情况下,由Spring自动生成代理对象提供新实例。

@Lookup 是xml配置标签look-up的注解实现。

一、<lookup-method/>标签

假设一个单例模式的bean A需要引用另外一个非单例模式的bean B,为了在我们每次引用的时候都能拿到最新的bean B,我们可以让bean A通过实现ApplicationContextWare来感知applicationContext(即可以获得容器上下文),从而能在运行时通过ApplicationContext.getBean(String beanName)的方法来获取最新的bean B。但是如果用ApplicationContextAware接口,就让我们与Spring代码耦合了,违背了反转控制原则(IoC,即bean完全由Spring容器管理,我们自己的代码只需要用bean就可以了)。
所以Spring为我们提供了方法注入的方式来实现以上的场景。方法注入方式主要是通过标签。

实例

下面我们用一个例子来说明lookup-method的用法。
假设有一个果盘,果盘里放了一些水果,比如苹果,香蕉等,我们希望我们每次在果盘里拿到的都是最新鲜的水果。
java代码:

// 定义一个水果类
public class Fruit {
    public Fruit() {
        System.out.println("I got Fruit");
    }
}

// 苹果
public class Apple extends Fruit {
    public Apple() {
        System.out.println("I got a fresh apple");
    }
}

// 香蕉
public class Bananer extends Fruit {
    public Bananer () {
        System.out.println("I got a  fresh bananer");
    }
}

// 水果盘,可以拿到水果
public abstract class FruitPlate{
    // 抽象方法获取新鲜水果
    protected abstract Fruit getFruit();
}

spring配置:

<!-- 这是2个非单例模式的bean -->
<bean id="apple" class="cn.com.willchen.test.di.Apple" scope="prototype"/>
<bean id="bananer" class="cn.com.willchen.test.di.Bananer " scope="prototype"/>
<bean id="fruitPlate1" class="cn.com.willchen.test.di.FruitPlate">
    <lookup-method name="getFruit" bean="apple"/>
</bean>
<bean id="fruitPlate2" class="cn.com.willchen.test.di.FruitPlate">
    <lookup-method name="getFruit" bean="bananer"/>
</bean>

测试代码:

public static void main(String[] args) {
    ApplicationContext app = new ClassPathXmlApplicationContext("classpath:resource/applicationContext.xml");

    FruitPlate fp1= (FruitPlate)app.getBean("fruitPlate1");
    FruitPlate fp2 = (FruitPlate)app.getBean("fruitPlate2");

    fp1.getFruit();
    fp2.getFruit();
}

测试结果:

I got Fruit
I got a fresh apple
I got Fruit
I got a fresh bananer

示例说明:
从上面例子我们可以看到,在代码中,我们没有用到Spring的任何类和接口,实现了与Spring代码的耦合。
其中,最为核心的部分就是lookup-method的配置和FruitPlate.getFruit()方法。上面代码中,我们可以看到getFruit()方法是个抽象方法,我们并没有实现它啊,那它是怎么拿到水果的呢。
这里的奥妙就是Srping应用了CGLIB(动态代理)类库。Spring在初始化容器的时候对配置的bean做了特殊处理,Spring会对bean指定的class做动态代理,代理标签中name属性所指定的方法,返回bean属性指定的bean实例对象。每次我们调用fruitPlate1或者fruitPlate2这2个bean的getFruit()方法时,其实是调用了CGLIB生成的动态代理类的方法。关于CGLIB大家可自行在网上查阅。
lookup-method实现方式说明:

<bean class="beanClass">
	<lookup-method name="method" bean="non-singleton-bean"/>
</bean>
二、@Lookup注解

实例
有一个单例的Boy类:

@Component
@Scope(scopeName = ConfigurableBeanFactory.SCOPE_SINGLETON) //原型 也就是非单例
public class Boy {
    public void playToy() {
        Toy toy = getToy();
        System.out.println(toy);
    }

    @Lookup
    public Toy getToy() {
        return null;
    }
}

然后他每次要playToy()的时候,都会生成一个新的Toy对象,Toy是原型类型的,并且用@Lookup注解修饰playToy()方法,方法体里面返回空,Spring会自动生成一个代理对象:

@Component
@Scope(scopeName= ConfigurableBeanFactory.SCOPE_PROTOTYPE) //原型 也就是非单例
public class Toy {

    public Toy() {
        System.out.println("Buy a new toy...");
    }
}

THE END.

<?xml version="1.0" encoding="UTF-8"?> <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"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.5.15</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.hzxy</groupId> <artifactId>AssistCase_GA</artifactId> <version>0.0.2-SNAPSHOT</version> <name>PublicSecurityAssistCase</name> <!--<packaging>war</packaging>--> <description>Demo project for Spring Boot</description> <!-- <properties>--> <!-- <java.version>1.8</java.version>--> <!-- <hutool.version>5.4.4</hutool.version>--> <!-- </properties>--> <properties> <java.version>17</java.version> <hutool.version>5.4.4</hutool.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-validation</artifactId> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-spring-boot-starter-jaxws</artifactId> <version>3.2.5</version> <exclusions> <exclusion> <artifactId>cxf-core</artifactId> <groupId>org.apache.cxf</groupId> </exclusion> <exclusion> <artifactId>spring-boot-autoconfigure</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> <exclusion> <artifactId>spring-boot-starter-web</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> <exclusion> <artifactId>spring-boot</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.1</version> </dependency> <dependency> <groupId>com.liferay</groupId> <artifactId>org.apache.commons.configuration</artifactId> <version>1.10.LIFERAY-PATCHED-2</version> </dependency> <!-- axis 1.4 jar start --> <dependency> <groupId>org.apache.axis</groupId> <artifactId>axis</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>commons-discovery</groupId> <artifactId>commons-discovery</artifactId> <version>0.2</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.axis</groupId> <artifactId>axis-jaxrpc</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>org.apache.axis</groupId> <artifactId>axis-saaj</artifactId> <version>1.4</version> </dependency> <dependency> <groupId>wsdl4j</groupId> <artifactId>wsdl4j</artifactId> <version>1.4</version> </dependency> <!-- axis 1.4 jar end --> <!--lib--> <!--<dependency>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-starter-tomcat</artifactId>--> <!--<scope>provided</scope>--> <!--</dependency>--> <!--<dependency>--> <!--<groupId>javax.servlet</groupId>--> <!--<artifactId>javax.servlet-api</artifactId>--> <!--<version>3.0.1</version>--> <!--<scope>provided</scope>--> <!--</dependency>--> <dependency> <groupId>com.hzxy.framework</groupId> <artifactId>common</artifactId> <version>0.0.54-SNAPSHOT</version> <exclusions> <exclusion> <artifactId>springfox-swagger-ui</artifactId> <groupId>io.springfox</groupId> </exclusion> <exclusion> <artifactId>spring-boot-starter-web</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> <exclusion> <artifactId>lombok</artifactId> <groupId>org.projectlombok</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.hzxy.framework</groupId> <artifactId>office_nmga</artifactId> <version>0.0.17-SNAPSHOT</version> <exclusions> <exclusion> <artifactId>springfox-swagger-ui</artifactId> <groupId>io.springfox</groupId> </exclusion> <exclusion> <artifactId>spring-boot-starter-web</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> <exclusion> <artifactId>lombok</artifactId> <groupId>org.projectlombok</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.hzxy.framework</groupId> <artifactId>multipleStorageTools_GA</artifactId> <version>0.0.5-SNAPSHOT</version> </dependency> <dependency> <groupId>io.dgraph</groupId> <artifactId>dgraph4j</artifactId> <version>20.03.3</version> <exclusions> <exclusion> <artifactId>guava</artifactId> <groupId>com.google.guava</groupId> </exclusion> <exclusion> <artifactId>netty-handler</artifactId> <groupId>io.netty</groupId> </exclusion> <exclusion> <artifactId>netty-common</artifactId> <groupId>io.netty</groupId> </exclusion> <exclusion> <artifactId>grpc-protobuf</artifactId> <groupId>io.grpc</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.org</groupId> <artifactId>dom4j</artifactId> <version>2.1.3</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/lib/dom4j-2.1.3.jar</systemPath> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20170516</version> </dependency> <dependency> <groupId>xom</groupId> <artifactId>xom</artifactId> <version>1.2.5</version> <exclusions> <exclusion> <artifactId>xml-apis</artifactId> <groupId>xml-apis</groupId> </exclusion> <exclusion> <artifactId>xercesImpl</artifactId> <groupId>xerces</groupId> </exclusion> <exclusion> <artifactId>xalan</artifactId> <groupId>xalan</groupId> </exclusion> </exclusions> </dependency> <!-- <dependency> <groupId>com.hzxy</groupId> <artifactId>instantmsg</artifactId> <scope>system</scope> <version>0.0.1-SNAPSHOT</version> <systemPath>${project.basedir}/src/main/resources/lib/instantmsg-0.0.1-SNAPSHOT.jar</systemPath> </dependency> --> <!--Swagger2--> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> <exclusions> <exclusion> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> </exclusion> <exclusion> <artifactId>guava</artifactId> <groupId>com.google.guava</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-models</artifactId> <version>1.5.21</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.10.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.5.15</version> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.1</version> <exclusions> <exclusion> <artifactId>mybatis</artifactId> <groupId>org.mybatis</groupId> </exclusion> <exclusion> <artifactId>spring-boot-autoconfigure</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.24</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.21</version> <exclusions> <exclusion> <artifactId>spring-boot-autoconfigure</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.shardingsphere</groupId> <artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId> <version>5.1.1</version> <exclusions> <exclusion> <artifactId>guava</artifactId> <groupId>com.google.guava</groupId> </exclusion> <exclusion> <artifactId>netty-handler</artifactId> <groupId>io.netty</groupId> </exclusion> <exclusion> <artifactId>netty-common</artifactId> <groupId>io.netty</groupId> </exclusion> <exclusion> <artifactId>json-path</artifactId> <groupId>com.jayway.jsonpath</groupId> </exclusion> </exclusions> </dependency> <!-- 使用druid连接池需要加dbcp依赖 --> <dependency> <groupId>org.apache.tomcat</groupId> <artifactId>tomcat-dbcp</artifactId> <version>10.0.16</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.4.1</version> <exclusions> <exclusion> <artifactId>mybatis-plus</artifactId> <groupId>com.baomidou</groupId> </exclusion> <exclusion> <artifactId>spring-boot-autoconfigure</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> </dependency> <!-- mybatis plus 代码生成器依赖 --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>3.4.1</version> </dependency> <!-- 代码生成器模板 --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <version>2.5.15</version> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> <exclusion> <artifactId>json-path</artifactId> <groupId>com.jayway.jsonpath</groupId> </exclusion> <exclusion> <artifactId>spring-boot-autoconfigure</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> <exclusion> <artifactId>spring-boot</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> <version>5.1.6</version> </dependency> <dependency> <groupId>com.auth0</groupId> <artifactId>java-jwt</artifactId> <version>2.2.0</version> </dependency> <!-- https://mvnrepository.com/artifact/net.sf.json-lib/json-lib --> <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</artifactId> <version>2.4</version> <classifier>jdk15</classifier> <exclusions> <exclusion> <artifactId>commons-beanutils</artifactId> <groupId>commons-beanutils</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.54</version> </dependency> <!--<dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>3.17</version> </dependency>--> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>4.1.2</version> <exclusions> <exclusion> <artifactId>commons-compress</artifactId> <groupId>org.apache.commons</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.2.7</version> </dependency> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.9.2</version> </dependency> <dependency> <groupId>net.coobird</groupId> <artifactId>thumbnailator</artifactId> <version>0.4.8</version> </dependency> <dependency> <groupId>org.elasticsearch</groupId> <artifactId>elasticsearch</artifactId> <version>7.17.23</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-elasticsearch</artifactId> <version>3.2.5.RELEASE</version> <exclusions> <exclusion> <artifactId>netty-handler</artifactId> <groupId>io.netty</groupId> </exclusion> <exclusion> <artifactId>netty-common</artifactId> <groupId>io.netty</groupId> </exclusion> <exclusion> <artifactId>elasticsearch</artifactId> <groupId>org.elasticsearch</groupId> </exclusion> <exclusion> <artifactId>elasticsearch-core</artifactId> <groupId>org.elasticsearch</groupId> </exclusion> <exclusion> <artifactId>joda-time</artifactId> <groupId>joda-time</groupId> </exclusion> </exclusions> </dependency> <!-- rabbit mq --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId> <version>2.5.15</version> <exclusions> <exclusion> <artifactId>spring-amqp</artifactId> <groupId>org.springframework.amqp</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> </dependency> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>${hutool.version}</version> </dependency> <dependency> <groupId>org.apache.ant</groupId> <artifactId>ant</artifactId> <version>1.10.11</version> </dependency> <dependency> <groupId>com.dm</groupId> <artifactId>Dm8JdbcDriver</artifactId> <version>1.7</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/lib/DmJdbcDriver18.jar</systemPath> </dependency> <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>pdfbox</artifactId> <version>2.0.24</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-jexl</artifactId> <version>2.0</version> </dependency> <dependency> <groupId>org.icepdf.os</groupId> <artifactId>icepdf-core</artifactId> <version>6.2.2</version> <exclusions> <exclusion> <groupId>javax.media</groupId> <artifactId>jai_core</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itext-pdfa</artifactId> <version>5.5.13</version> </dependency> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itext-asian</artifactId> <version>5.2.0</version> </dependency> <!-- pdf样式 --> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itext-asian</artifactId> <version>5.2.0</version> </dependency> <!--pdf相关操作--> <dependency> <groupId>com.itextpdf</groupId> <artifactId>itextpdf</artifactId> <version>5.5.10</version> </dependency> <dependency> <groupId>com.drewnoakes</groupId> <artifactId>metadata-extractor</artifactId> <version>2.14.0</version> </dependency> <!-- <dependency>--> <!-- <groupId>org.springframework</groupId>--> <!-- <artifactId>spring-test</artifactId>--> <!-- <version>RELEASE</version>--> <!-- </dependency>--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-elasticsearch</artifactId> <version>2.5.15</version> <exclusions> <exclusion> <groupId>org.elasticsearch.client</groupId> <artifactId>transport</artifactId> </exclusion> <exclusion> <artifactId>spring-data-elasticsearch</artifactId> <groupId>org.springframework.data</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.elasticsearch.client</groupId> <artifactId>x-pack-transport</artifactId> <version>6.8.16</version> </dependency> <dependency> <groupId>uk.com.robust-it</groupId> <artifactId>cloning</artifactId> <version>1.9.12</version> </dependency> <dependency> <groupId>com.aspose.words</groupId> <artifactId>aspose</artifactId> <version>15.8.0.0</version> <scope>system</scope> <systemPath>${project.basedir}/src/main/resources/lib/aspose-words-15.8.0-jdk16.jar</systemPath> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.5.15</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot</artifactId> <version>2.5.15</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-autoconfigure</artifactId> <version>2.5.15</version> <exclusions> <exclusion> <artifactId>spring-boot</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> </exclusions> </dependency> <!-- <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.3.29</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>5.3.29</version> <exclusions> <exclusion> <artifactId>spring-beans</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-messaging</artifactId> <version>5.3.29</version> <exclusions> <exclusion> <artifactId>spring-beans</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>5.3.29</version> <exclusions> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>6.1.13</version> <exclusions> <exclusion> <artifactId>spring-beans</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-expression</artifactId> <groupId>org.springframework</groupId> </exclusion> <exclusion> <artifactId>spring-web</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <version>5.3.39</version> <exclusions> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus</artifactId> <version>3.5.3.1</version> </dependency> <dependency> <groupId>io.grpc</groupId> <artifactId>grpc-protobuf</artifactId> <version>1.53.0</version> </dependency> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>2.5.0</version> <exclusions> <exclusion> <artifactId>spring-boot-autoconfigure</artifactId> <groupId>org.springframework.boot</groupId> </exclusion> <exclusion> <artifactId>spring-webmvc</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>32.0.0-android</version> </dependency> <dependency> <groupId>commons-beanutils</groupId> <artifactId>commons-beanutils</artifactId> <version>1.9.4</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-compress</artifactId> <version>1.26.0</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.5.6</version> </dependency> <dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.12.2</version> </dependency> <dependency> <groupId>xalan</groupId> <artifactId>xalan</artifactId> <version>2.7.3</version> </dependency> <dependency> <groupId>org.springframework.amqp</groupId> <artifactId>spring-amqp</artifactId> <version>2.2.20.RELEASE</version> <exclusions> <exclusion> <artifactId>spring-core</artifactId> <groupId>org.springframework</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-core</artifactId> <version>3.5.8</version> </dependency> <dependency> <groupId>com.jayway.jsonpath</groupId> <artifactId>json-path</artifactId> <version>2.9.0</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-common</artifactId> <version>4.1.116.Final</version> </dependency> <dependency> <groupId>io.netty</groupId> <artifactId>netty-handler</artifactId> <version>4.1.100.Final</version> <exclusions> <exclusion> <artifactId>netty-common</artifactId> <groupId>io.netty</groupId> </exclusion> </exclusions> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>com.fasterxml.jackson</groupId> <artifactId>jackson-bom</artifactId> <version>2.13.5</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <repositories> <!-- add the elasticsearch repo --> <!-- 必须加上 这个仓库,不然x-pack-transport6.8.6在其他仓库中没有--> <repository> <id>elasticsearch-releases</id> <url>https://artifacts.elastic.co/maven</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <distributionManagement> <repository> <id>nexus-releases</id> <name>Local Nexus Repository</name> <url>http://192.168.3.102:8082/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Local Nexus Repository</name> <url>http://192.168.3.102:8082/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement> <build> <plugins> <!--如果是打jar包,则需在build的plugins中添加如下配置--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>2.5.15</version> <configuration> <!--值为true是指打包时包含scope为system的第三方Jar包--> <includeSystemScope>true</includeSystemScope> </configuration> </plugin> </plugins> <!--<plugins>--> <!--<plugin>--> <!--<groupId>org.springframework.boot</groupId>--> <!--<artifactId>spring-boot-maven-plugin</artifactId>--> <!--</plugin>--> <!--<plugin>--> <!--<groupId>org.apache.maven.plugins</groupId>--> <!--<artifactId>maven-compiler-plugin</artifactId>--> <!--<version>${maven-compiler-plugin.version}</version>--> <!--<configuration>--> <!--<source>1.8</source>--> <!--<target>1.8</target>--> <!--<skip>true</skip>--> <!--<encoding>UTF-8</encoding>--> <!--<compilerArguments>--> <!--<extdirs>${project.basedir}/src/main/resources/lib</extdirs>--> <!--<!–extdirs>lib</extdirs>–>--> <!--</compilerArguments>--> <!--</configuration>--> <!--</plugin>--> <!--<plugin>--> <!--<groupId>org.apache.maven.plugins</groupId>--> <!--<artifactId>maven-war-plugin</artifactId>--> <!--<version>3.1.0</version>--> <!--<configuration>--> <!--<webResources>--> <!--<resource>--> <!--<directory>src/main/resources/lib/</directory>--> <!--<targetPath>WEB-INF/lib/</targetPath>--> <!--<includes>--> <!--<include>**/*.jar</include>--> <!--</includes>--> <!--</resource>--> <!--</webResources>--> <!--<failOnMissingWebXml>false</failOnMissingWebXml>--> <!--</configuration>--> <!--</plugin>--> <!--</plugins>--> </build> </project> 上述是我项目的pom文件启动报错 Error creating bean with name 'catalogueOcrTimer' defined in file [D:\work\nmGA_DB\Code\back\PublicSecurityAssistCase_back\target\classes\com\hzxy\PublicSecurityAssistCase\Timer\CatalogueOcrTimer.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabAutoCatalogueTaskServiceImpl': Unsatisfied dependency expressed through field 'autoCatalogueService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'autoCatalogueService': Unsatisfied dependency expressed through field 'tabTrailProcessOperateCompleteService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabTrailProcessOperateCompleteServiceImpl': Unsatisfied dependency expressed through field 'tabCaseFolderTreeService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabCaseFolderTreeServiceImpl': Unsatisfied dependency expressed through field 'tabCaseFolderTemplateTreeServiceImpl'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabCaseFolderTemplateTreeServiceImpl': Unsatisfied dependency expressed through field 'tabCaseXsshFolderResultService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabCaseXsshFolderResultServiceImpl': Unsatisfied dependency expressed through field 'tabCaseService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabCaseServiceImpl': Unsatisfied dependency expressed through field 'tabCaseStatisticsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabCaseStatisticsServiceImpl': Unsatisfied dependency expressed through field 'elasticSearchService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchServiceImpl' defined in file [D:\work\nmGA_DB\Code\back\PublicSecurityAssistCase_back\target\classes\com\hzxy\PublicSecurityAssistCase\service\es\Impl\ElasticsearchServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHighLevelClient' defined in class path resource [com/hzxy/PublicSecurityAssistCase/config/ElasticsearchConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'restHighLevelClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/common/xcontent/ToXContentObject Error creating bean with name 'tabAutoCatalogueTaskServiceImpl': Unsatisfied dependency expressed through field 'autoCatalogueService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'autoCatalogueService': Unsatisfied dependency expressed through field 'tabTrailProcessOperateCompleteService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabTrailProcessOperateCompleteServiceImpl': Unsatisfied dependency expressed through field 'tabCaseFolderTreeService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabCaseFolderTreeServiceImpl': Unsatisfied dependency expressed through field 'tabCaseFolderTemplateTreeServiceImpl'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabCaseFolderTemplateTreeServiceImpl': Unsatisfied dependency expressed through field 'tabCaseXsshFolderResultService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabCaseXsshFolderResultServiceImpl': Unsatisfied dependency expressed through field 'tabCaseService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabCaseServiceImpl': Unsatisfied dependency expressed through field 'tabCaseStatisticsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'tabCaseStatisticsServiceImpl': Unsatisfied dependency expressed through field 'elasticSearchService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchServiceImpl' defined in file [D:\work\nmGA_DB\Code\back\PublicSecurityAssistCase_back\target\classes\com\hzxy\PublicSecurityAssistCase\service\es\Impl\ElasticsearchServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHighLevelClient' defined in class path resource [com/hzxy/PublicSecurityAssistCase/config/ElasticsearchConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'restHighLevelClient' threw exception; nested exception is java.lang.NoClassDefFoundError: org/elasticsearch/common/xcontent/ToXContentObject
07-10
<?xml version="1.0" encoding="UTF-8"?> <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"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.5.7</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.huang</groupId> <artifactId>huang</artifactId> <version>0.0.1-SNAPSHOT</version> <name>huang</name> <description>huang</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>17</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-spring-boot3-starter</artifactId> <version>3.5.6</version> </dependency> <!-- mysql驱动依赖 --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>8.0.31</version> </dependency> <!-- druid 连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.2.23</version> </dependency> <!-- lombok --> <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.42</version> </dependency> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId> <version>4.4.0</version> </dependency> <!-- pagehelper 分页 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>2.1.0</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.14.1</version> <configuration> <annotationProcessorPaths> <!-- 可以留空,使用默认的注解处理器路径,或完全移除该段 --> </annotationProcessorPaths> </configuration> </plugin> </plugins> </build> </project> pom相关内容
最新发布
11-23
<?xml version="1.0" encoding="UTF-8"?> <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"> <modelVersion>4.0.0</modelVersion> <!-- 父依赖:Spring Boot 3.3.1 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.3.1</version> <relativePath/> <!-- 从仓库获取父依赖 --> </parent> <!-- 项目基本信息 --> <groupId>com.example</groupId> <artifactId>main</artifactId> <version>0.0.1</version> <name>main</name> <description>为Spring Cloud Alibaba升级铺垫的主服务</description> <!-- 版本管理(统一控制依赖版本,避免冲突) --> <properties> <java.version>17</java.version> <encoding>UTF-8</encoding> <project.build.sourceEncoding>${encoding}</project.build.sourceEncoding> <project.reporting.outputEncoding>${encoding}</project.reporting.outputEncoding> <maven.compiler.encoding>${encoding}</maven.compiler.encoding> <!-- Spring Cloud Alibaba 版本(适配Spring Boot 3.3.x) --> <spring-cloud-alibaba.version>2023.0.1.0</spring-cloud-alibaba.version> <!-- Spring Cloud 版本(与Alibaba配套) --> <spring-cloud.version>2023.0.2</spring-cloud.version> <!-- 第三方工具版本 --> <mybatis-plus.version>3.5.7</mybatis-plus.version> <fastjson2.version>2.0.52</fastjson2.version> <modelmapper.version>3.2.1</modelmapper.version> <jjwt.version>0.11.5</jjwt.version> <redisson.version>3.50.0</redisson.version> <hutool.version>5.8.32</hutool.version> <!-- 统一hutool版本 --> <poi.version>5.4.0</poi.version> <druid.version>1.2.13</druid.version> <minio.version>8.5.12</minio.version> <taos-jdbcdriver.version>3.5.3</taos-jdbcdriver.version> <xxl-job.version>2.4.1</xxl-job.version> <activiti.version>7.1.0.M6</activiti.version> <springdoc.version>2.1.0</springdoc.version> <!-- <powerjob.version>5.1.1</powerjob.version>--> <californium.version>3.5.0</californium.version> <wechatpay-sdk.version>0.6.0</wechatpay-sdk.version> <alipay-sdk.version>4.34.0.ALL</alipay-sdk.version> <volc-sdk.version>LATEST</volc-sdk.version> </properties> <!-- 依赖管理(控制Spring Cloud Alibaba及相关组件版本) --> <dependencyManagement> <dependencies> <!-- Spring Cloud Alibaba 核心依赖管理 --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>${spring-cloud-alibaba.version}</version> <type>pom</type> <scope>import</scope> </dependency> <!-- Spring Cloud 核心依赖管理 --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>jakarta.annotation</groupId> <artifactId>jakarta.annotation-api</artifactId> <version>2.1.1</version> </dependency> <!-- 一、Spring Boot 核心 Starter --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> <!-- 排除 Tomcat 的旧版注解 API --> <exclusion> <groupId>org.apache.tomcat</groupId> <artifactId>annotations-api</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-aop</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <!-- 服务监控,Alibaba生态必备 --> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- 二、Spring Cloud Alibaba 核心组件(为升级铺垫) --> <!-- 服务注册与发现(Nacos) --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!-- 声明式服务调用(OpenFeign) --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency> <!-- 熔断限流(Sentinel,已存在,保留) --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency> <!-- 消息队列(RocketMQ,与Alibaba生态兼容) --> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-stream-rocketmq</artifactId> <!-- 替换原生rocketmq-starter,适配Alibaba --> </dependency> <!-- 三、安全与认证 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-oauth2-authorization-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-oauth2-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-oauth2-resource-server</artifactId> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> <!-- JWT工具 --> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-api</artifactId> <version>${jjwt.version}</version> </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-impl</artifactId> <version>${jjwt.version}</version> <scope>runtime</scope> </dependency> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt-jackson</artifactId> <version>${jjwt.version}</version> <scope>runtime</scope> </dependency> <!-- 四、数据访问 --> <!-- MySQL驱动 --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <!-- MongoDB --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <!-- Redis(Redisson作为客户端,已排除原生Redis starter避免冲突) --> <dependency> <groupId>org.redisson</groupId> <artifactId>redisson-spring-boot-starter</artifactId> <version>${redisson.version}</version> <exclusions> <exclusion> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </exclusion> </exclusions> </dependency> <!-- MyBatis-Plus(适配Spring Boot 3) --> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-spring-boot3-starter</artifactId> <version>${mybatis-plus.version}</version> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-generator</artifactId> <version>${mybatis-plus.version}</version> </dependency> <!-- 数据库连接池(Druid) --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>${druid.version}</version> </dependency> <!-- 五、消息与通信 --> <!-- WebSocket --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-websocket</artifactId> </dependency> <!-- Kafka(如需保留,与RocketMQ并存需注意配置隔离) --> <dependency> <groupId>org.springframework.kafka</groupId> <artifactId>spring-kafka</artifactId> </dependency> <dependency> <groupId>org.springframework.kafka</groupId> <artifactId>spring-kafka-test</artifactId> <scope>test</scope> </dependency> <!-- CoAP协议 --> <dependency> <groupId>org.eclipse.californium</groupId> <artifactId>californium-core</artifactId> <version>${californium.version}</version> </dependency> <!-- 六、工具类 --> <!-- JSON处理(FastJSON2) --> <dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2</artifactId> <version>${fastjson2.version}</version> </dependency> <!-- 对象转换(ModelMapper) --> <dependency> <groupId>org.modelmapper</groupId> <artifactId>modelmapper</artifactId> <version>${modelmapper.version}</version> </dependency> <!-- Hutool工具集(已包含captcha,移除单独的hutool-captcha) --> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>${hutool.version}</version> </dependency> <!-- Excel处理(POI) --> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi</artifactId> <version>${poi.version}</version> </dependency> <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxml</artifactId> <version>${poi.version}</version> </dependency> <!-- Lombok --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!-- 七、业务组件 --> <!-- 文件存储(MinIO) --> <dependency> <groupId>io.minio</groupId> <artifactId>minio</artifactId> <version>${minio.version}</version> </dependency> <!-- 时序数据库(TAOS) --> <dependency> <groupId>com.taosdata.jdbc</groupId> <artifactId>taos-jdbcdriver</artifactId> <version>${taos-jdbcdriver.version}</version> </dependency> <!-- 任务调度(XXL-Job) --> <dependency> <groupId>com.xuxueli</groupId> <artifactId>xxl-job-core</artifactId> <version>${xxl-job.version}</version> </dependency> <!-- 工作流(Activiti) --> <dependency> <groupId>org.activiti</groupId> <artifactId>activiti-spring-boot-starter</artifactId> <version>${activiti.version}</version> </dependency> <dependency> <groupId>org.activiti.core.common</groupId> <artifactId>activiti-spring-security</artifactId> <version>${activiti.version}</version> </dependency> <!-- 分布式任务调度(PowerJob) --> <!-- <dependency>--> <!-- <groupId>com.github.kfcfans</groupId>--> <!-- <artifactId>powerjob-client</artifactId>--> <!-- <version>${powerjob.version}</version>--> <!-- </dependency>--> <!-- 八、支付相关 --> <dependency> <groupId>com.github.wechatpay-apiv3</groupId> <artifactId>wechatpay-apache-httpclient</artifactId> <version>${wechatpay-sdk.version}</version> </dependency> <dependency> <groupId>com.alipay.sdk</groupId> <artifactId>alipay-sdk-java</artifactId> <version>${alipay-sdk.version}</version> </dependency> <!-- 九、API文档(Swagger) --> <dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>${springdoc.version}</version> </dependency> <!-- 十、火山引擎SDK --> <dependency> <groupId>com.volcengine</groupId> <artifactId>volcengine-java-sdk-ark-runtime</artifactId> <version>${volc-sdk.version}</version> </dependency> <dependency> <groupId>com.volcengine</groupId> <artifactId>volc-sdk-java</artifactId> <version>${volc-sdk.version}</version> </dependency> </dependencies> <!-- 仓库配置(优先使用阿里云仓库加速) --> <repositories> <repository> <id>aliyun</id> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url> <snapshots> <enabled>false</enabled> <!-- 关闭快照版本下载 --> </snapshots> </repository> <!-- Spring Cloud Alibaba 专属仓库(确保依赖下载) --> <repository> <id>spring-cloud-alibaba</id> <name>Spring Cloud Alibaba Repository</name> <url>https://maven.aliyun.com/repository/spring</url> </repository> </repositories> <!-- 构建配置 --> <build> <plugins> <!-- Spring Boot 打包插件 --> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> <!-- 多环境配置 --> <profiles> <profile> <id>dev</id> <activation> <activeByDefault>true</activeByDefault> </activation> <properties> <spring-boot.run.profiles>dev</spring-boot.run.profiles> </properties> </profile> <profile> <id>prod</id> <properties> <spring-boot.run.profiles>prod</spring-boot.run.profiles> </properties> </profile> </profiles> </configuration> </plugin> <!-- 编译插件(指定Java版本) --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.11.0</version> <configuration> <source>${java.version}</source> <target>${java.version}</target> <encoding>${encoding}</encoding> </configuration> </plugin> </plugins> <!-- 资源文件配置 --> <resources> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.xml</include> <include>**/*.properties</include> <include>**/*.yml</include> <!-- 补充yml文件支持 --> </includes> <filtering>false</filtering> <!-- 不启用过滤 --> </resource> <!-- 多环境配置文件过滤 --> <resource> <directory>src/main/resources</directory> <includes> <include>application.properties</include> <include>application-${profiles.active}.properties</include> <include>application-${profiles.active}.yml</include> </includes> <filtering>true</filtering> <!-- 启用变量替换 --> </resource> </resources> </build> <!-- 多环境配置 --> <profiles> <profile> <id>dev</id> <properties> <profiles.active>dev</profiles.active> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>prod</id> <properties> <profiles.active>prod</profiles.active> </properties> </profile> </profiles> </project> 这是我的pom报错了 3.5.7 19:09:36.166 [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'deviceAdminService': Error creating bean with name 'deviceAdminServiceImpl' defined in file [E:\core\main\target\classes\com\example\main\service\device\impl\DeviceAdminServiceImpl.class]: Post-processing of merged bean definition failed 19:09:36.183 [main] INFO o.a.catalina.core.StandardService - Stopping service [Tomcat] 19:09:36.204 [main] WARN o.a.c.loader.WebappClassLoaderBase - The web application [ROOT] appears to have started a thread named [Thread-2] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: java.base@17.0.14/sun.net.dns.ResolverConfigurationImpl.notifyAddrChange0(Native Method) java.base@17.0.14/sun.net.dns.ResolverConfigurationImpl$AddressChangeListener.run(ResolverConfigurationImpl.java:176) 19:09:36.224 [main] INFO o.s.b.a.l.ConditionEvaluationReportLogger - Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 19:09:36.246 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter - *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$LegacyResourceElement.<init>(CommonAnnotationBeanPostProcessor.java:780) The following method did not exist: 'java.lang.String javax.annotation.Resource.lookup()' The calling method's class, org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$LegacyResourceElement, was loaded from the following location: jar:file:/E:/maven-repository/org/springframework/spring-context/6.1.10/spring-context-6.1.10.jar!/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor$LegacyResourceElement.class The called method's class, javax.annotation.Resource, is available from the following locations: jar:file:/E:/maven-repository/org/apache/tomcat/annotations-api/6.0.53/annotations-api-6.0.53.jar!/javax/annotation/Resource.class jar:file:/E:/maven-repository/javax/annotation/javax.annotation-api/1.3.2/javax.annotation-api-1.3.2.jar!/javax/annotation/Resource.class The called method's class hierarchy was loaded from the following locations: javax.annotation.Resource: file:/E:/maven-repository/org/apache/tomcat/annotations-api/6.0.53/annotations-api-6.0.53.jar Action: Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$LegacyResourceElement and javax.annotation.Resource Disconnected from the target VM, address: '127.0.0.1:3673', transport: 'socket'
08-15
<?xml version="1.0" encoding="UTF-8"?> <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"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.5.4</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>edu.bw</groupId> <artifactId>springboot-data</artifactId> <version>0.0.1-SNAPSHOT</version> <name>springboot-data</name> <description>springboot-data</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>21</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> <optional>true</optional> </dependency> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>8.0.33</version> </dependency> <!--连接池--> <!-- <dependency>--> <!-- <groupId>com.alibaba</groupId>--> <!-- <artifactId>druid</artifactId>--> <!-- <version>1.2.24</version>--> <!-- </dependency>--> <!-- druid连接池--> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.23</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> #连接池的配置 spring: datasource: druid: username: root password: lwf123456 url: jdbc:mysql://localhost:3306/springboot? useUnicode=true&characterEncoding=utf-8&useSSL=false driver-class-name: com.mysql.cj.jdbc.Driver initial-size: 100 max-active: 100 min-idle: 2 报错 Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception with message: Failed to determine a suitable driver class
08-19
<?xml version="1.0" encoding="UTF-8"?> <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"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>3.5.3</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.example</groupId> <artifactId>wjdc</artifactId> <version>0.0.1-SNAPSHOT</version> <name>wjdc</name> <description>wjdc</description> <properties> <java.version>17</java.version> </properties> <dependencies> <!-- Spring Boot Web 依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <!-- MySQL 驱动 --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <scope>runtime</scope> </dependency> <!-- 原生 MyBatis 依赖(适配 Spring 3.x) --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>3.0.3</version> <!-- 最新版适配 Spring 3.x --> </dependency> <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus-boot-starter</artifactId> <version>3.5.7</version> </dependency> <!-- Lombok 依赖 --> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <!-- 测试依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <!-- MyBatis 代码生成器核心依赖 --> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.4.1</version> </dependency> </dependencies> <build> <plugins> <!-- MyBatis 代码生成器 Maven 插件 --> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.4.1</version> <configuration> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> <dependencies> <!-- 数据库驱动依赖(生成器需要) --> <dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> <version>9.2.0</version> <!-- 与项目驱动版本一致 --> </dependency> </dependencies> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <excludes> <exclude> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </exclude> </excludes> </configuration> </plugin> </plugins> </build> </project>报错Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2025-07-05T21:12:00.447+08:00 ERROR 10268 --- [wjdc] [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder.parse(MybatisMapperAnnotationBuilder.java:122) The following method did not exist: 'void org.apache.ibatis.session.Configuration.parsePendingMethods(boolean)' The calling method's class, com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder, was loaded from the following location: jar:file:/D:/work/kaifa/huanjing/maven/apache-maven-3.9.10/com/baomidou/mybatis-plus-core/3.5.7/mybatis-plus-core-3.5.7.jar!/com/baomidou/mybatisplus/core/MybatisMapperAnnotationBuilder.class The called method's class, org.apache.ibatis.session.Configuration, is available from the following locations: jar:file:/D:/work/kaifa/huanjing/maven/apache-maven-3.9.10/org/mybatis/mybatis/3.5.14/mybatis-3.5.14.jar!/org/apache/ibatis/session/Configuration.class The called method's class hierarchy was loaded from the following locations: org.apache.ibatis.session.Configuration: file:/D:/work/kaifa/huanjing/maven/apache-maven-3.9.10/org/mybatis/mybatis/3.5.14/mybatis-3.5.14.jar Action: Correct the classpath of your application so that it contains compatible versions of the classes com.baomidou.mybatisplus.core.MybatisMapperAnnotationBuilder and org.apache.ibatis.session.Configuration
07-06
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值