So folks were following this tutorial: DataSource in Tomcat only when implementing the part of CDI of the project I ran with the following error:
com/mycompany/soft/util/TransactionInterceptor.java:[13,22] cannot find symbol
symbol: variable Priority
location: @interface javax.interceptor.Interceptor
1 error
I just followed the example with the code examples in GitHub and I have no idea where the error is.
The class that generates the error follows:
package com.mycompany.soft.util;
import java.io.Serializable;
import javax.annotation.Priority;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
@Transactional
@Interceptor
@Priority(Interceptor.Priority.LIBRARY_BEFORE)
public class TransactionInterceptor implements Serializable {
private static final long serialVersionUID = 1L;
private @Inject
EntityManager manager;
@AroundInvoke
public Object invoke(InvocationContext context) throws Exception {
EntityTransaction trx = manager.getTransaction();
boolean criador = false;
try {
if (!trx.isActive()) {
// truque para fazer rollback no que já passou
// (senão, um futuro commit, confirmaria até mesmo operações sem transação)
trx.begin();
trx.rollback();
// agora sim inicia a transação
trx.begin();
criador = true;
}
return context.proceed();
} catch (Exception e) {
if (trx != null && criador) {
trx.rollback();
}
throw e;
} finally {
if (trx != null && trx.isActive() && criador) {
trx.commit();
}
}
}
}
And now my Pom, it's a bit different from his, but even with the same dependencies as his, the error continued ...
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.soft</groupId>
<artifactId>Soft</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- Dependências da camada de apresentação - INÍCIO -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>6.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.14</version>
<scope>compile</scope>
</dependency>
<!-- Dependências da camada de apresentação - FIM -->
<!-- Driver do MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<!-- Driver do Jasper -->
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.1.1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.3.Final</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<!-- Dependências para auxiliar no upload - INÍCIO -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.jboss.weld.servlet</groupId>
<artifactId>weld-servlet</artifactId>
<version>2.4.7.Final</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is the link for his project that I relied on: Link