I developed a small web-application to Tomcat8 to just discover that I should deploy it in Tomcat7. Downgrading such app to Tom7 is not an easy task, but what is bottering me is that I've got an error in creating the BasicDataSource from the library org.apache.tomcat.dbcp.dbcp2.BasicDataSource
.
This library can be found in commons-dbcp2 dependency in Maven. Nevertheless, in spite of getting this in my POM, either Eclipse IDE and mvn install
are not finding the reference and everything has melt down. Comming back to Tom8 didn't solved the problem, and I am wondering what configuration in Eclipse and Maven is messed up.
Q: How to solve this DPC2 dependency/configuration in order to run application on Tomcat 7, if possible?
Any help would be worth. Thanks.
POM:
<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</groupId>
<artifactId>myApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>Application Name</name>
<description>Application Description</description>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.12.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.0.5.Final</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>5.0.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>2.0.2.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.2.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
</dependencies>
</project>
JAVA:
@Bean(name="restDataSource")//Bean name adicionado posteriormente. Pode gerar problemas.
public DataSource restDataSource() {
BasicDataSource dataSource = new BasicDataSource(); //"BasicDataSource cannot be resolved to a type"
dataSource.setDriverClassName(env.getProperty("database.driver"));
dataSource.setUrl(env.getProperty("database.url"));
dataSource.setUsername(env.getProperty("database.user"));
dataSource.setPassword(env.getProperty("database.password"));
dataSource.setInitialSize(Integer.valueOf(env.getProperty("pool.initialSize")));
dataSource.setMaxIdle(Integer.valueOf(env.getProperty("pool.maxIdle")));
dataSource.setMinIdle(Integer.valueOf(env.getProperty("pool.minIdle")));
dataSource.setMaxTotal(Integer.valueOf(env.getProperty("pool.maxActive")));
return dataSource;
}
MAVEN ERROR:
[ERROR] location: class com.mycompany.PersistenceConfiguration
[ERROR] /foo/bar/.../conf/PersistenceConfiguration.java:[51,40] cannot find symbol
[ERROR] symbol: class BasicDataSource