構建施耐德樓控系統資料庫後台伺服器樣本工程—(工程建立),施耐德控系統

來源:互聯網
上載者:User

構建施耐德樓控系統資料庫後台伺服器樣本工程—(工程建立),施耐德控系統

工作中需要在施耐德樓控系統上添加後台管理功能和手機控制功能,單位採購的施耐德的產品僅僅是用於控制現場裝置的樓控模組及上位機編程與HMI,我們需要在此基礎上,自主開發手機端控制功能,那麼就需要通過建立後台工程用於往施耐德的硬體上發訊號或者修改其資料庫。

本文即是建立在此想法的基礎上,記錄一下如何採用Spring、Hibernate、Rest這個架構構建一個可以快速開發的後台管理架構。

1.使用eclipse建立一個普通JAVA工程


2.右鍵工程名,選擇屬性,點擊"Project Facets"將“Dynamic Web Module勾選上,一個動態Web工程即建好


3.將Spring、Hibernate、Rest所需的jar檔案全部複製到Web工程的WEB-INF/lib檔案夾下(建議將jar檔案複製到工程下面而不是引用,否則還需在tomcat下面放置一份jar包,否則會照成運行時報錯)

4.建立Web.xml用於配置Spring資訊

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:javaee="http://java.sun.com/xml/ns/javaee"xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"version="2.4"><display-name>TacControlServerWeb</display-name><distributable /><context-param><param-name>contextConfigLocation</param-name><param-value>            classpath:/spring/applicationContext*.xml        </param-value></context-param><filter><filter-name>encodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param><init-param><param-name>forceEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>encodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><listener><!-- 自動裝配ApplicationContext的配置資訊 --><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><listener><!-- org.springframework.web.util.IntrospectorCleanupListener監聽器主要負責處理由JavaBean Introspector使用而引起的緩衝泄露 --><listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class></listener><listener><!-- ContextLoaderListener實現ServletContextListener監聽器介面,而ServletContextListener只負責監聽Web容器的啟動和關閉的事件。RequestContextFilter實現ServletRequestListener監聽器介面,該監聽器監聽HTTP請求事件,Web伺服器接收的每次請求都會通知該監聽器。通過配置RequestContextFilter,Spring容器與Web容器結合的更加密切。 --><listener-class>org.springframework.web.context.request.RequestContextListener</listener-class></listener><!-- rest監聽器配置 --><servlet><display-name>JAX-RS REST Servlet</display-name><servlet-name>JAX-RS REST Servlet</servlet-name><servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class><init-param><param-name>com.sun.jersey.config.property.packages</param-name><param-value>szx.rest</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>JAX-RS REST Servlet</servlet-name><url-pattern>/szxrest/*</url-pattern></servlet-mapping><servlet><description></description><display-name>FindInfo</display-name><servlet-name>FindInfo</servlet-name><servlet-class>szx.web.servlet.FindInfo</servlet-class></servlet><servlet-mapping><servlet-name>FindInfo</servlet-name><url-pattern>/FindInfo</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list></web-app>
5.配置了Spring後,在Spring的設定檔中配置Hibernate資訊和自動注入的方式,如下applicationContext-core.xml

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"xmlns:context="http://www.springframework.org/schema/context"xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-2.5.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-2.5.xsdhttp://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-2.5.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><context:property-placeholder location="classpath:jdbc.properties" /><bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroy-method="close"><property name="driverClassName" value="${jdbc.driverClassName}" /><property name="url" value="${jdbc.url}" /><property name="username" value="${jdbc.username}" /><property name="password" value="${jdbc.password}" /><property name="maxActive" value="2000" /><property name="maxIdle" value="1000"></property><property name="maxWait" value="25000" /><property name="poolPreparedStatements" value="false" /><property name="defaultAutoCommit" value="true" /></bean><!-- Hibernate SessionFactory --><bean id="sessionFactory"class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"><property name="dataSource" ref="dataSource" /><property name="packagesToScan"><list><value>szx</value></list></property><property name="hibernateProperties"><value>hibernate.dialect=${hibernate.dialect}hibernate.query.substitutions=true 'Y', false 'N'hibernate.cache.use_second_level_cache=truehibernate.cache.provider_class=org.hibernate.cache.EhCacheProviderhibernate.jdbc.fetch_size=50hibernate.jdbc.batch_size=25hibernate.show_sql=truehibernate.format_sql=falsehibernate.use_sql_comments=true</value></property><property name="lobHandler" ref="lobHandler" /></bean><bean id="lobHandler" class="org.springframework.jdbc.support.lob.OracleLobHandler"><property name="nativeJdbcExtractor" ref="nativeJdbcExtractor" /></bean><bean id="nativeJdbcExtractor"class="org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor" /><!-- Transaction manager for a single Hibernate SessionFactory --><bean id="transactionManager"class="org.springframework.orm.hibernate3.HibernateTransactionManager"><property name="sessionFactory" ref="sessionFactory" /></bean><!-- Enable annotation-based configuration --><context:annotation-config /><!-- Enable classpath scanning for managed components --><context:component-scan base-package="szx" name-generator="szx.core.spring.CustomBeanNameGenerator"/><!-- Enable @AspectJ support --><aop:aspectj-autoproxy /><!-- Enable @Transactional support --><tx:annotation-driven /><aop:config><aop:advisor advice-ref="txAdvice"pointcut="execution(* *..service.*Manager.*(..))" order="100" /></aop:config><tx:advice id="txAdvice"><tx:attributes><tx:method name="*" rollback-for="Throwable" /></tx:attributes></tx:advice></beans>
6.建立jdbc.properties檔案,設定資料庫串連(資料庫可以適配MySQL、Oracle、SqlServer)

#hibernate.dialect=cn.walle.core.support.hibernate.Oracle10gDialecthibernate.dialect=org.hibernate.dialect.SQLServerDialect#jdbc.driverClassName=oracle.jdbc.driver.OracleDriver#jdbc.driverClassName=com.microsoft.jdbc.sqlserver.SQLServerDriver#jdbc.url=jdbc:sqlserver://localhost:1433;integratedSecurity=true;DatabaseName=taclogdatajdbc.driverClassName=net.sourceforge.jtds.jdbc.Driverjdbc.url=jdbc:jtds:sqlserver://localhost:1433;integratedSecurity=true;DatabaseName=taclogdata#jdbc.url=jdbc:oracle:thin:@192.168.103.9:1521:orcl#jdbc.url=jdbc:oracle:thin:@219.237.193.91:1521:orcl#jdbc.url=jdbc:oracle:thin:@iwmds.rdh.com:1521:orcljdbc.username=tacvistajdbc.password=tacvista
7.工程結構如






聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.