Skip to content

Commit 002f39e

Browse files
committed
6_13_tomcat_pool_jndi_cargo
1 parent bf6d6ca commit 002f39e

4 files changed

Lines changed: 113 additions & 2 deletions

File tree

‎pom.xml‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1818
<spring.version>5.3.39</spring.version>
1919
<spring-data-jpa.version>2.7.18</spring-data-jpa.version>
20-
<tomcat.version>9.0.111</tomcat.version>
20+
<tomcat.version>9.0.113</tomcat.version>
2121

2222
<!-- Hibernate -->
2323
<hibernate.version>5.6.15.Final</hibernate.version>
@@ -64,6 +64,48 @@
6464
<argLine>-Dfile.encoding=UTF-8</argLine>
6565
</configuration>
6666
</plugin>
67+
68+
<!-- http://stackoverflow.com/questions/4305935/is-it-possible-to-supply-tomcat6s-context-xml-file-via-the-maven-cargo-plugin#4417945 -->
69+
<!-- https://codehaus-cargo.github.io/cargo/Tomcat+9.x.html -->
70+
<plugin>
71+
<groupId>org.codehaus.cargo</groupId>
72+
<artifactId>cargo-maven3-plugin</artifactId>
73+
<version>1.10.26</version>
74+
<configuration>
75+
<container>
76+
<containerId>tomcat9x</containerId>
77+
<systemProperties>
78+
<file.encoding>UTF-8</file.encoding>
79+
<spring.profiles.active>tomcat,datajpa</spring.profiles.active>
80+
</systemProperties>
81+
<dependencies>
82+
<dependency>
83+
<groupId>org.postgresql</groupId>
84+
<artifactId>postgresql</artifactId>
85+
</dependency>
86+
</dependencies>
87+
</container>
88+
<configuration>
89+
<configfiles>
90+
<configfile>
91+
<file>src/main/resources/tomcat/context.xml</file>
92+
<todir>conf/Catalina/localhost/</todir>
93+
<tofile>${project.build.finalName}.xml</tofile>
94+
</configfile>
95+
</configfiles>
96+
</configuration>
97+
<deployables>
98+
<deployable>
99+
<groupId>ru.javawebinar</groupId>
100+
<artifactId>topjava</artifactId>
101+
<type>war</type>
102+
<properties>
103+
<context>${project.build.finalName}</context>
104+
</properties>
105+
</deployable>
106+
</deployables>
107+
</configuration>
108+
</plugin>
67109
</plugins>
68110
</build>
69111

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
database.init=false
2+
jdbc.initLocation=classpath:db/initDB.sql
3+
jpa.showSql=true
4+
hibernate.format_sql=true
5+
hibernate.use_sql_comments=true

‎src/main/resources/spring/spring-db.xml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
66
xmlns:tx="http://www.springframework.org/schema/tx"
77
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
8+
xmlns:jee="http://www.springframework.org/schema/jee"
89
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
910
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
1011
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
1112
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
12-
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
13+
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
14+
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">
1315

1416
<jdbc:initialize-database data-source="dataSource" enabled="${database.init}">
1517
<jdbc:script location="${jdbc.initLocation}"/>
@@ -50,6 +52,11 @@
5052
p:password="${database.password}"/>
5153
</beans>
5254

55+
<beans profile="tomcat">
56+
<jee:jndi-lookup id="dataSource" jndi-name="java:comp/env/jdbc/topjava"/>
57+
<context:property-placeholder location="classpath:db/tomcat.properties" system-properties-mode="OVERRIDE"/>
58+
</beans>
59+
5360
<beans profile="jdbc">
5461
<context:component-scan base-package="ru.javawebinar.**.repository.jdbc"/>
5562
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version='1.0' encoding='utf-8'?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<!-- The contents of this file will be loaded for each web application -->
19+
<Context>
20+
21+
<!-- Default set of monitored resources. If one of these changes, the -->
22+
<!-- web application will be reloaded. -->
23+
<WatchedResource>WEB-INF/web.xml</WatchedResource>
24+
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
25+
26+
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
27+
<!--
28+
<Manager pathname="" />
29+
-->
30+
31+
<!-- Uncomment this to enable Comet connection tacking (provides events
32+
on session expiration as well as webapp lifecycle) -->
33+
<!--
34+
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
35+
-->
36+
<Resource name="jdbc/topjava"
37+
auth="Container"
38+
type="javax.sql.DataSource"
39+
url="jdbc:postgresql://localhost:5432/topjava"
40+
username="user"
41+
password="password"
42+
driverClassName="org.postgresql.Driver"
43+
validationQuery="SELECT 1"
44+
maxTotal="10"
45+
minIdle="2"
46+
maxWaitMillis="20000"
47+
initialSize="2"
48+
maxIdle="5"
49+
testOnBorrow="true"
50+
removeAbandonedOnBorrow="true"
51+
testWhileIdle="true"/>
52+
<!--
53+
username="wegxlfzjjgxaxy"
54+
password="SSQyKKE_e93kiUCR-ehzMcKCxZ"
55+
url="jdbc:postgresql://ec2-54-217-202-110.eu-west-1.compute.amazonaws.com:5432/dehm6lvm8bink0?ssl=true&amp;sslfactory=org.postgresql.ssl.NonValidatingFactory"/>
56+
-->
57+
</Context>

0 commit comments

Comments
 (0)