In pom.xml I use spring-tx-4.1.4.RELEASE.jar, but maven compiles the project with an error:
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project transaction: Compilation failure
\p4_projects\transaction\src\main\java\com\sick\dao\hibernate\DeviceModelDaoHibernate.java:[25,15] cannot find symbol symbol : method value()
location: #interface org.springframework.transaction.annotation.Transactional
I cannot find the reason. Dependency Hierarchy shows correct version 4.1.4 for all spring dependencies. I have the same result with 4.1.3.
I'll appreciate your help.
Thanks,
Elena
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import com.sick.dao.DeviceModelDao;
import com.sick.model.DeviceModel;
#Repository
#Transactional(value = "primary")
public class DeviceModelDaoHibernate implements DeviceModelDao {
private SessionFactory sessionFactory;
public DeviceModelDaoHibernate() {
}
public DeviceModelDaoHibernate(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
#Override
public void save(DeviceModel deviceModel) {
sessionFactory.getCurrentSession().saveOrUpdate(deviceModel);
}
}
pom.xml is too big to post here, therefore I publish only versions of dependencies:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<red5-server.version>1.0.2-SNAPSHOT</red5-server.version>
<red5-client.version>1.0.2-SNAPSHOT</red5-client.version>
<camel.version>2.14.1</camel.version>
<hibernate.version>4.3.8.Final</hibernate.version>
<spring.version>4.1.4.RELEASE</spring.version>
<spring-security.version>3.2.5.RELEASE</spring-security.version>
<spring-integration.version>3.0.0.RELEASE</spring-integration.version>
<slf4j.version>1.7.5</slf4j.version>
<mina.version>2.0.7</mina.version>
<logback.version>1.0.13</logback.version>
<junit.version>4.10</junit.version>
<cargo.host>localhost</cargo.host>
<cargo.port>25888</cargo.port>
<cargo.wait>false</cargo.wait>
<tomcat.version>6.0.14</tomcat.version>
</properties>
....
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<type>jar</type>
</dependency>
</dependencies>
Using Eclipse?
Try Maven clean > Project clean > Maven install.
Error is suspicious indeed, I think you do not have problem with code but with Maven.
Thanks to everybody, I have already resolved that issue. In pom.xml I've placed all org.springframework dependencies before org.hibernate dependencies and the problem has gone.
Same problem here: the #Transactional was wrongly coming from an old "spring-dao" library, wich was a transitive dependency for "spring-hibernate3" but I wanted it from "spring-tx".
Solved it by moving the "spring-tx" dependency before the "spring-hibernate3" (I supposed I could have used exclusions too).
Use mvn dependency:tree to visualize transitive dependencies.
Related
This is my first springboot crud. Please help me to fix the errors .
package com.example1.fullstack_practice;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
#SpringBootTest
class FullstackPracticeApplicationTests {
#Test
void contextLoads() {
}
}
You have to add the dependency to your class path. If you are using maven add:
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
to your pom.xml
I have the following Java code which errors on when I run
mvn clean install
In my source code, I have the following imports
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
and in my pom.xml I had the following
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
</dependency>
and I was getting the following error
error: package javax.persistence does not exist
I thought that maybe there was an error with the entry in the pom, so I tried to change the pom to the following
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
and I still get the following error. I am not sure what's causing the issue and how to fix it.
Try to replace it with
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
I am getting cannot resolve symbol for the following in my intelliJ project:
Data, Lombok, Component, beans, http, util
My Class
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
#Component
#ConfigurationProperties("c")
#Data
public class CP {
private String maxTasks;
private String subscribeTo;
}
My POM
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
</dependency>
Try
File -> Settings -> search for “Annotations” -> Enable annotations -> Select the “Enable annnotations”
Apply and Ok and then restart IntelliJ once.
To make work propertly lombok on intellij it is necessary to use the extension
https://plugins.jetbrains.com/plugin/6317-lombok
I am using Java based config with Maven, I've minimized the setup in order to isolate the error, yet I have no idea what is causing it except for the fact that removing the #EnableWebMvc annotation (which I obviously need) allows test to start and pass.
ExampleTest.java
package co.farel.server.services.test;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import co.farel.server.services.test.config.WebConfig;
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(classes={WebConfig.class})
public class ExampleTest {
#Test
public void test() {
assertEquals(true, true);
}
}
WebConfig.java
package co.farel.server.services.test.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
#EnableWebMvc
#Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
}
pom.xml
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mikolaj.nalecz.testy</groupId>
<artifactId>junit-spring-hibernate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
</dependencies>
</project>
When I try to run the test, I get:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [co.farel.server.services.test.config.WebConfig]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
The entire stacktrace http://pastebin.com/0DxXAS0P.
You are getting this error because you have invalid import statements in your project.
Most likely the invalid import is as following:
import org.springframework.context.annotation.Configuration;
Try adding the following dependencies to you POM:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.2.5.RELEASE</version>
</dependency>
Please add annotation #WebAppConfiguration to your Test Class
Hope this helps
Thanks
The problem was probably caused by the fact that the container will provide Java servlet classes at runtime, however during the tests I need a jar to provide them.
After adding:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
To pom.xml and:
#WebAppConfiguration
To my ExampleTest.java, everything works great.
package com.shaun.spring.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
#Configuration
#ComponentScan("com.shaun.spring")
#EnableTransactionManagement
public class ApplicationContextConfig {
// #Bean configurations go here...
}
i have a problem with #EnableTransactionManagement
the following error that occurs is:EnableTransactionManagement cannot be resolved to a type.
i have the following dependency in my pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
i have also tried using the following import:
import org.springframework.transaction.annotation.EnableTransactionManagement;
this gave me the following error:
The import org.springframework.transaction.annotation.EnableTransactionManagement cannot be resolved
You are missing the spring-orm dependency for Object Relational Mapping.
Just import it into your pom file
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>
I had to just re add the jar file to the libraries in my project and the class was there. thanks for help meriton
If you develop in the IntelliJ, right click in the POM file and add as a Maven project. It should solve the issue.
Before
After