IntelliJ has been throwing "Cannot resolve symbol 'JmsTemplate'" for the past few days, when creating a jmsTemplate bean.
Here's my TestConfig.groovy file the error is thrown.
`
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;
}
}
`
Here's my dependencies in 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'
}
Here's the stacktrace.
> 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
I've tried to resolve this using multiple techniques I managed to find online with no effect.
- Delete the .idea folder and re-launch the project.
- Invalidate caches and restart.
- Re-installed the JDK and added it to the path
- Made sure the correct SDK is set in the File->Project Structure settings.
- Checked the Language Level of the modules and the Java Compiler.
- Tried to add the @EnableJms
Nothing works and I don't understand why..
CodePudding user response:
I managed to find the answer.
One of my dependencies had a version too high.
testImplementation "org.springframework:spring-jms:6.0.3"
Once I lowered the version to 5.3.24 it all started working fine.
testImplementation "org.springframework:spring-jms:5.3.24"