Mysql Netbeans/Glassfish-不使用sun-resources.xml与jdbc连接
我正在尝试让一个Netbeans/Glassfish企业应用程序在我的pc上本地运行,它目前正在生产中。我已经看到登录显示,但当我尝试登录时,应用程序会抛出以下异常:Mysql Netbeans/Glassfish-不使用sun-resources.xml与jdbc连接,mysql,netbeans,jdbc,glassfish,Mysql,Netbeans,Jdbc,Glassfish,我正在尝试让一个Netbeans/Glassfish企业应用程序在我的pc上本地运行,它目前正在生产中。我已经看到登录显示,但当我尝试登录时,应用程序会抛出以下异常: SEVERE: "com.sun.enterprise.security.auth.login.common.LoginException: Login failed: javax.security.auth.login.LoginException: Failed file login for myloginname". 登
SEVERE: "com.sun.enterprise.security.auth.login.common.LoginException: Login failed: javax.security.auth.login.LoginException: Failed file login for myloginname".
登录servlet将转发到登录错误页面
-web项目中的web.xml如下所示:
<resource-ref>
<res-ref-name>jdbc/my_name_MySQL</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
还有一个persistence.xml设置,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="modCompJar-PU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/my_name_MySQL</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.SunONETransactionManagerLookup"/>
<property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory"/>
<property name="hibernate.search.default.indexBase" value="/opt/index/webInput"/>
</properties>
</persistence-unit>
</persistence>
最后,还有一个sun-resources.xml,如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Resource Definitions //EN" "http://www.sun.com/software/appserver/dtds/sun-resources_1_3.dtd">
<resources>
<jdbc-resource enabled="true" jndi-name="jdbc/my_name_MySQL" object-type="user" pool-name="MyPool">
<description/>
</jdbc-resource>
<jdbc-connection-pool allow-non-component-callers="false" associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" connection-validation-method="auto-commit" datasource-classname="com.mysql.jdbc.Driver" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" is-isolation-level-guaranteed="true" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="false" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="MyPool" non-transactional-connections="false" pool-resize-quantity="2" res-type="javax.sql.DataSource" statement-timeout-in-seconds="-1" steady-pool-size="8" validate-atmost-once-period-in-seconds="0" wrap-jdbc-objects="false">
<property name="URL" value="jdbc:mysql://localhost:33306/mydatabsename?relaxAutoCommit="true""/>
<property name="User" value="root"/>
</jdbc-connection-pool>
</resources>
注意,我通过Putty设置了一个隧道来使用远程数据库,因此33306用于mysql端口,而不是3306
我还使用隧道端口将Netbeans更改为指向远程服务器的数据库。这是因为单击服务下的数据库节点会显示与远程服务器上存在的数据库相同的数据库
我知道登录是正确的,因为当我登录到服务器上运行的应用程序时,我就进入了,它们都在访问同一个数据库
我还注意到在domain.xml中设置了一些jdbc连接池,它们引用了不存在的数据库和ip地址。唯一有效的数据库是上面显示的数据库,位于sun-resources.xml中
如何使此应用程序连接到正确的数据库