Intellij Idea IntelliJ Sping Boot -创建Bean时“无法解析符号”JmsTemplate“”

dgtucam1  于 2023-01-01  发布在  其他
关注(0)|答案(1)|浏览(270)

IntelliJ在过去几天创建jmsTemplate Bean时一直抛出“无法解析符号'JmsTemplate'”。
这是我的TestConfig.groovy文件,错误被抛出。
'

package automation.test

import org.apache.activemq.ActiveMQConnectionFactory
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.SpringBootConfiguration
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.jms.core.JmsTemplate

import javax.jms.ConnectionFactory

@SpringBootConfiguration
@EnableJms
class TestConfig {
    @Value('${activemq.host}')
    private String brokerUrl

    @Bean
    public ConnectionFactory connectionFactory() {
        ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
        activeMQConnectionFactory.setBrokerURL(brokerUrl)
        return activeMQConnectionFactory
    }

    @Bean
    public JmsTemplate jmsTemplate() {
        JmsTemplate jmsTemplate = new JmsTemplate()
        jmsTemplate.setConnectionFactory(connectionFactory())
        jmsTemplate.setReceiveTimeout(10000)
        return jmsTemplate;
    }
}

'
以下是我在build.gradle中的依赖项

dependencies {
    implementation "org.springframework.boot:spring-boot-starter-data-jpa:2.2.6.RELEASE"
    implementation "org.codehaus.groovy:groovy-all:3.0.9"
    implementation "org.codehaus.groovy:groovy-yaml:3.0.9"
    implementation "org.apache.httpcomponents:httpclient:4.5.12"
    implementation group: "org.apache.activemq", name: "activemq-client", version: "5.15.12"
    implementation group: 'org.springframework', name: 'spring-jms', version: '6.0.3'

    implementation "com.oracle.database.jdbc:ojdbc10:19.3.0.0"

    testImplementation "org.spockframework:spock-core:2.0-M2-groovy-3.0"
    testImplementation "org.spockframework:spock-spring:2.0-M2-groovy-3.0"
    testImplementation "com.github.tomakehurst:wiremock-jre8:2.35.0"

    testImplementation "org.springframework:spring-tx:5.2.5.RELEASE"
    testImplementation "org.springframework.boot:spring-boot-starter-test:2.2.6.RELEASE"
    testImplementation "org.springframework:spring-jms:6.0.3"

    testImplementation 'org.slf4j:slf4j-api:1.7.29'

    implementation group: 'javax.jms', name: 'javax.jms-api', version: '2.0.1'
    implementation group: 'org.apache.activemq', name: 'activemq-client', version: '5.16.0'

    implementation 'com.mashape.unirest:unirest-java:1.4.9'

    implementation 'com.google.code.findbugs:jsr305:3.0.2'
}

这是堆栈跟踪。

> Task :generateMainEffectiveLombokConfig1
> Task :compileJava NO-SOURCE
> Task :compileGroovy
startup failed:
unable to resolve class org.springframework.jms.core.JmsTemplate
 @ line 8, column 1.
   import org.springframework.jms.core.JmsTemplate
   ^
1 error
> Task :compileGroovy FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
2 actionable tasks: 2 executed

我试着用我在网上找到的多种技术来解决这个问题,但没有效果。
1.删除.idea文件夹并重新启动项目。
1.使缓存无效并重新启动。
1.已重新安装JDK并将其添加到路径
1.确保在文件-〉项目结构设置中设置了正确的SDK。
1.已检查模块和Java编译器的语言级别。
1.尝试添加@EnableJms
什么都不管用我不明白为什么..

4dc9hkyq

4dc9hkyq1#

我设法找到了答案。
我的一个依赖项的版本太高。

testImplementation "org.springframework:spring-jms:6.0.3"

一旦我将版本降低到5.3.24,一切都开始正常工作。

testImplementation "org.springframework:spring-jms:5.3.24"

相关问题