Struts2-spring-hibernate-proxool Configuration

Source: Internet
Author: User

The project is finished. However, the project performance is quite poor. As mentioned above, check whether the connection pool is not closed, so the pool will soon be filled up?

For this reason, I want to monitor information in the connection pool.

First

Thanks for the online example.

Proxool. xml

Bytes -----------------------------------------------------------------------------------------------------------------

<? XML version = "1.0" encoding = "UTF-8"?>
<Proxool-config>
<Proxool>

<! -- Specify an alias for the data source -->
<Alias> dB </alias>
<Driver-URL> JDBC: mysql: // localhost: 3306/books? Useunicode = true & amp; characterencoding = UTF-8 </driver-URL>
<Driver-class> com. MySQL. JDBC. Driver </driver-class>

<Driver-Properties>

<! -- Database login username -->
<Property name = "user" value = "root"/>

<! -- Database Login User Password -->
<Property name = "password" value = "root"/>
</Driver-Properties>
<House-keeping-sleep-time> 90000 <! -- The maximum number of requests waiting in the queue because no idle connections can be allocated.
User connection will not be accepted (official database 10, test database 1) -->
<Maximum-New-connections> 20 </maximum-New-connections>
<! -- Minimum number of idle connections (official database 10, test database 1) -->
<Prototype-count> 10 </prototype-count>
<! -- Maximum number of connections allowed by the connection pool (official database 700, Test Database 10) -->
<Maximum-connection-count> 1000 </maximum-connection-count>
<! -- Minimum number of connections enabled in the connection pool (official database 350, test database 5) -->
<Minimum-connection-count> 350 </minimum-connection-count>

<! -- The maximum time of an active connection is 15 minutes, in milliseconds -->
<Maximum-active-time> 900000 </maximum-active-time>
<! -- The maximum activity time of a connection is 4 hours, in milliseconds -->
<Maximum-connection-lifetime> 14400000 </maximum-connection-lifetime>
<! -- Automatically checks whether the connection is disconnected -->
<Test-before-use> true </test-before-use>
<! -- Test SQL statement that automatically checks whether the connection is disconnected -->
<House-keeping-test-SQL> select sysdate () from dual </Proxool>
</Proxool-config>

 

Bytes --------------------------------------------------------------------------------------------------------

This is dB. XML (spring)

Bytes --------------------------------------------------------------------------------------------------------

<? XML version = "1.0" encoding = "UTF-8"?>
<Beans
Xmlns = "http://www.springframework.org/schema/beans"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<Bean id = "datasource"
Class = "org. springframework. JDBC. datasource. drivermanagerdatasource">
<Property name = "driverclassname">
<Value> org. logicalcobwebs. proxool. proxooldriver </value>
</Property>
<Property name = "url">

<! -- Here the URL references the preceding alias proxool. DB -->
<Value> proxool. DB </value>
</Property>
</Bean>
<Bean id = "sessionfactory"
Class = "org. springframework. Orm. hibernate3.localsessionfactorybean">
<Property name = "datasource">
<Ref bean = "datasource"/>
</Property>
<Property name = "mappingdirectorylocations">
<List>
<Value> classpath: COM/mobile/HBM/</value>
</List>
</Property>
<Property name = "hibernateproperties">
<Props>
<Prop key = "hibernate. dialect">
Org. hibernate. dialect. mysqldialect
</Prop>
<Prop key = "hibernate. show_ SQL">
True
</Prop>
</Props>
</Property>
</Bean>
</Beans>

Bytes --------------------------------------------------------------------------------------------------------------

This is a problem with Web. xml.

I have found many examples on the Internet.

<Listener>
<Listener-class>
Org. springframework. Web. Context. contextloaderlistener
</Listener-class>
</Listener>

Replace

<Servlet>
<Servlet-Name> contextconfiglocation </servlet-Name>
<Servlet-class>
Org. springframework. Web. Context. contextloaderservlet
</Servlet-class>
<Load-on-startup> 2 </load-on-startup>
</Servlet>

An error occurred after replacement. Spring cannot have no listeners. Must be added.

If listener is used directly without replacement

Java. SQL. sqlexception: org. logicalcobwebs. proxool. proxoolexception: attempt to refer to a unregistered pool by its alias 'db'

This error occurs. If this error occurs on the Internet, the listener should be replaced.

An error occurred while replacing it.

I don't know what to do now.

Continue searching online. You can see a blog with the same error.

The blog says:

 

But there is a problem, so when struts2 is integrated with spring, Web. spring loading in XML must be loaded by listener. If contextloderservlet is used, an exception is thrown, indicating somewhere in the objectfactory of struts2, because the loading sequence of most web containers is: listener, filter, Servlet, so struts2 will be loaded before spring, and it will not find the spring management container, resulting in exceptions. The solution is to use contextloderlistener to load spring, in this way, the problem occurs again. Spring has an exception, and it will not find our applicationcontext. the alias of the data source provided by XML, that is, proxool. dbpool, unable to manage the database connection pool, it seems that struts2 and proxool are fish and bear's paw, both cannot have both, it seems we can't do it now, what should we do?
Method 1: Do not use proxool (nonsense, do not use it to write this article );
Method 2: The proxool load is changed from servlet to listener, but the proxool official does not provide the class for listener loading. we can write a listener for implementation.

 

He wrote a listener class according to his method. The problem persists.

 

Bytes --------------------------------------------------------------------------------------------------------

<? XML version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee
Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd>
 
<Servlet>
<Servlet-Name> servletconfigurator </servlet-Name>
<Servlet-class>
Org. logicalcobwebs. proxool. configuration. servletconfigurator
</Servlet-class>
<Init-param>
<Param-Name> xmlfile </param-Name>
<Param-value> WEB-INF/proxool. xml </param-value>
</Init-param>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
<Servlet>
<Servlet-Name> contextconfiglocation </servlet-Name>
<Servlet-class>
Org. springframework. Web. Context. contextloaderservlet
</Servlet-class>
<Load-on-startup> 2 </load-on-startup>
</Servlet>
 
<Servlet>
<Servlet-Name> admin </servlet-Name>
<Servlet-class>
Org. logicalcobwebs. proxool. admin. servlet. adminservlet
</Servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> admin </servlet-Name>
<URL-pattern>/admin </url-pattern>
</Servlet-mapping>
<! -- Spring configuration file location -->
<Context-param>
<Param-Name> contextconfiglocation </param-Name>
<Param-value> classpath *: Spring-config/*. xml </param-value>
</Context-param>

<! -- Log4j attribute file location -->
<Context-param>
<Param-Name> log4jconfiglocation </param-Name>
<Param-value>/WEB-INF/classes/log4j. properties </param-value>
</Context-param>

<! -- Disable the session after the session is delayed to the View Interface -->
<Filter>
<Filter-Name> opensession </filter-Name>
<Filter-class>
Org. springframework. Orm. hibernate3.support. opensessioninviewfilter
</Filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> opensession </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>
 
 
<! -- Struts2 clears the action instance left by the previous request before the request -->
<Filter>
<Filter-Name> struts2-cleanup </filter-Name>
<Filter-class>
Org. Apache. struts2.dispatcher. actioncontextcleanup
</Filter-class>
</Filter>

<Filter-mapping>
<Filter-Name> struts2-cleanup </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>
 
<! -- Struts2 filter -->
<Filter>
<Filter-Name> struts2 </filter-Name>
<Filter-class>
Org. Apache. struts2.dispatcher. filterdispatcher
</Filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> struts2 </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>

<Welcome-file-List>
<Welcome-File> index. jsp </welcome-File>
</Welcome-file-List>
</Web-app>
Bytes ----------------------------------------------------------------------------------------

Now this problem occurs again:

Com. MySQL. JDBC. Exceptions. jdbc4.mysqlnontransientconnectionexception: Data Source rejected Establishment of connection, message from server: "Too has connections"

Excuse me:

Org. logicalcobwebs. proxool. proxoolexception: attempt to refer to a unregistered pool by its alias 'db' how can this problem be solved?

 

If there is a struts2-spring-plugin-2.0.11.jar, this jar has to write the listener.

There are many ways to remove this on the Internet.

I tried to remove it,

Appears:

Cannot locate the chosen objectfactory implementation: Spring-[unknown location]

 

How does one configure the proxool configuration?

What kind of thinking is it?

Who can help me?

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.