MySQL 데이터베이스 및 최대 절전 모드를 사용하여 Netbeans 6.5에서 Java 웹 응용 프로그램을 개발했습니다. 개발 데이터베이스 서버와 개발 애플리케이션 서버 (Tomcat 6)는 모두 내 개발 시스템에 있습니다. 모든 것이 작동합니다. 응용 프로그램이 데이터베이스에서 데이터를 올바르게 가져옵니다.Netbeans Dev에서 Tomcat 제작 : DB 연결을 찾을 수 없음
이제 프로덕션 서버로 이동할 준비가되었습니다. 다시 DB 서버와 응용 프로그램 서버는 동일한 시스템에 있습니다. WAR 파일을 배포하고 응용 프로그램에 액세스하려고합니다. 나는 정적 페이지 만 제외하고 데이터베이스 오류를 사용하는 서블릿에 액세스 할 수 있습니다
org.hibernate.exception.JDBCConnectionException: Cannot open connection
내가 Tomcat이 데이터 소스에 대해 모르는에 문제가 관련이 확신 해요. 그것은 마치 Netbeans이 나를 위해 처리하는 것 같습니다.
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/EmployeeDirectory">
<Resource
name="jdbc/employeedirectory" auth="Container"
type="javax.sql.DataSource" username="EmployeeDir"
password="EmployeeDirectory" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://127.0.0.1:3306/EmployeeDirectory?autoReconnect=true"
maxActive="15" maxIdle="7"
validationQuery="Select 1" />
</Context>
의 web.xml 파일 :
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<!-- Omit Servlet Info -->
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/employeedirectory</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
그리고 내가 나에게의 context.xml에 준 this site에서 몇 가지 조언을했다, 그래서 나는 자원 항목을 추가해야 할 수도 있습니다 읽었습니다 의 hibernate.cfg.xml 내 :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.datasource">java:comp/env/jdbc/employeedirectory</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Omit other Mappings -->
<mapping class="EmployeeDirectory.data.PhoneNumber" resource="EmployeeDirectory/data/PhoneNumber.hbm.xml"/>
</session-factory>
</hibernate-configuration>
지금, 나는 org.hibernate.HibernateException: Could not find datasource
오류가 발생합니다.
개발에서 생산으로 이동하기위한 올바른 길을 가고 있습니까? 내가 뭘 놓치고 있니?