2013-08-20 18 views
16

Tôi đang sử dụng Spring3.2.0 phát hành vì vậy tôi đã cố gắng để viết dưới đây applicationContext.xml tập tinLàm thế nào để viết tệp Spring ApplicationContext.xml?

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     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" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 

     <!-- 
       This will automatically locate any and all property files you have 
       within your classpath, provided they fall under the META-INF 
       directory. The located property files are parsed and their values can 
       then be used within application context files in the form of 
       ${propertyKey}. 
     --> 
     <context:property-placeholder location="classpath*:*.properties" /> 
</beans> 

Nhưng điều này tập tin xml đưa ra lỗi trong Eclipse biên tập

Multiple annotations found at this line: 
    - cvc-elt.1: Cannot find the declaration of element 'beans'. 
    - schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring- 
    beans-3.0.xsd', because 1) could not find the document; 
      2) the document could not be read; 
      3) the root element of the 
    document is not <xsd:schema>. 

Vì vậy, tôi đã thay đổi tập tin applicationcontext.xml tôi như này

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     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" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.0.xsd"> 

     <!-- 
       This will automatically locate any and all property files you have 
       within your classpath, provided they fall under the META-INF 
       directory. The located property files are parsed and their values can 
       then be used within application context files in the form of 
       ${propertyKey}. 
     --> 
     <context:property-placeholder location="classpath*:*.properties" /> 
</beans> 

Chỉ thay đổi bạn sẽ thấy xsd khai báo trước đây tôi đã sử dụng 3.0.xsd và bây giờ 3.2.0.xsd vì vậy bây giờ vấn đề biên tập nhật thực đi nhưng bây giờ khi tôi đang chạy dự án thành Tomcat7, thời gian chạy tôi đang nhận được dưới đây ngoại lệ

org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans-3.2.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.util.ErrorHandlerWrapper.warning(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaWarning(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131) ~[spring-context-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537) ~[spring-context-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451) ~[spring-context-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) ~[catalina.jar:7.0.42] 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) ~[catalina.jar:7.0.42] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[catalina.jar:7.0.42] 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) ~[catalina.jar:7.0.42] 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) ~[catalina.jar:7.0.42] 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) ~[na:1.7.0_25] 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) ~[na:1.7.0_25] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25] 
    at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25] 
12:20:23.289 [localhost-startStop-1] ERROR o.s.web.context.ContextLoader - Context initialization failed 
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 6 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 578; cvc-elt.1: Cannot find the declaration of element 'beans'. 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131) ~[spring-context-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537) ~[spring-context-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451) ~[spring-context-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939) ~[catalina.jar:7.0.42] 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434) ~[catalina.jar:7.0.42] 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[catalina.jar:7.0.42] 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559) ~[catalina.jar:7.0.42] 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549) ~[catalina.jar:7.0.42] 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) ~[na:1.7.0_25] 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) ~[na:1.7.0_25] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25] 
    at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25] 
Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'. 
    at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.parsers.DOMParser.parse(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source) ~[xercesImpl-2.8.1.jar:na] 
    at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388) ~[spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE] 
    ... 23 common frames omitted 

Tôi không thể tìm ra vấn đề tôi đã tìm kiếm cho vấn đề trong google nhưng không có giải pháp nào được nêu ra, có ai giúp tôi viết tập tin applicationContext.xml không?

+0

tôi sẽ khuyên bạn nên tải về một trong những dự án từ https://github.com/SpringSource và sử dụng rằng applicationContext.xml tập tin – Algorithmist

+0

có rất nhiều dự án, nhưng tôi đã không nhận được tập tin xml – Programmer

Trả lời

15

Sử dụng này:

http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 

Xem Index of schema's cho danh sách của mùa xuân XSD. XSD cho spring-beans có thể được tìm thấy trong http://www.springframework.org/schema/beans/

+0

Đây có phải là quy tắc để viết tệp applicationContext không? – Programmer

+0

XML phải hợp lệ. Vì vậy, bạn phải tham chiếu các XSD hiện có. –

4

1) Đảm bảo rằng bạn thực sự triển khai spring-beans-3.2.x.RELEASE.jar. Nó chứa một tệp spring.schemas trong thư mục META-INF của nó (nó phải chứa url của vị trí lược đồ mà bạn sử dụng) và một tệp spring-beans-3.2.xsd trong thư mục org.springframework.beans.factory.xml.

2) Phiên bản XSD chỉ chứa hai phần (chính và nhỏ) 3.2 nhưng không phải 3.2.0!

BTW: bạn có thể sử dụng spring-XXX.xsd mà không phiên bản, sau đó sử dụng mùa xuân lúc nào cũng là phiên bản mới nhất (quy định tại spring.schemas tập tin)

+0

Tôi đang sử dụng Maven và trong hội thảo triển khai Eclipse, tôi đã thêm tất cả các lọ – Programmer

+0

Làm việc cho tôi. "không có phiên bản, sau đó mùa xuân luôn sử dụng phiên bản mới nhất" - Tôi không biết điều đó. Cảm ơn gợi ý. – sura2k

3

Thay thế trong ngữ cảnh của bạn xml tập tin http://www.springframework.org/schema/beans/spring-beans-3.0.xsd bởi http://www.springframework.org/schema/beans/spring-beans-3.2.xsd

2

Thay đổi XML của bạn như sau.

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     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" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.springframework.org/schema/aop 
          http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
          http://www.springframework.org/schema/context 
          http://www.springframework.org/schema/context/spring-context-3.2.xsd 
          http://www.springframework.org/schema/jee 
          http://www.springframework.org/schema/jee/spring-jee-3.2.xsd 
          http://www.springframework.org/schema/tx 
          http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> 

     <!-- 
       This will automatically locate any and all property files you have 
       within your classpath, provided they fall under the META-INF 
       directory. The located property files are parsed and their values can 
       then be used within application context files in the form of 
       ${propertyKey}. 
     --> 
     <context:property-placeholder location="classpath*:*.properties" /> 
</beans> 

Phiên bản XSD phải là 3.2 không 3.2.0

0

tôi đã nhận được cùng một lỗi n = nhưng nó đã giải quyết bằng cách sử dụng dưới đây bối cảnh ứng dụng tập tin

<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="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-3.0.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-3.0.3.xsd"> 

    <http auto-config="true"> 
     <intercept-url pattern="/welcome*" access="ROLE_USER" /> 
    </http> 

    <authentication-manager> 
     <authentication-provider> 
     <user-service> 
     <user name="mkyong" password="123456" authorities="ROLE_USER" /> 
     </user-service> 
     </authentication-provider> 
    </authentication-manager> 

</beans:beans> 

và dưới đây là danh sách file jar của tôi,

commons-logging-1.1.1.jar 
spring-aop-3.0.3.RELEASE.jar 
spring-asm-3.0.5.RELEASE.jar 
spring-beans-3.0.5.RELEASE.jar 
spring-context-3.0.5.RELEASE.jar 
spring-core-3.0.5.RELEASE.jar 
spring-expression-3.0.5.RELEASE.jar 
spring-security-config-3.0.5.RELEASE.jar 
spring-security-core-3.0.5.RELEASE.jar 
spring-security-web-3.0.5.RELEASE.jar 
spring-tx-3.0.3.RELEASE.jar 
spring-web-3.0.5.RELEASE.jar 
spring-webmvc-3.0.5.RELEASE.jar 
1

Đối với JMS bên Listener, bạn có thể áp dụng khái niệm này:

<?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:jms="http://www.springframework.org/schema/jms" 

    xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/jms 
    http://www.springframework.org/schema/jms/spring-jms-3.0.xsd"> 

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" 
p:brokerURL="tcp://localhost:61616" /> 

<bean id="listener" class="com.jms.MyMessageListener"></bean> 

<jms:listener-container container-type="default" connection-factory="connectionFactory" 
acknowledge="auto"> 
    <jms:listener destination="myqueue" ref="listener" method="onMessage"></jms:listener> 
</jms:listener-container> 

</beans> 

Đối với JMS Sender Side, bạn có thể áp dụng khái niệm này:

<?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:context="http://www.springframework.org/schema/context" 
    xmlns:jms="http://www.springframework.org/schema/jms" 

    xmlns:p="http://www.springframework.org/schema/p" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/jms 
    http://www.springframework.org/schema/jms/spring-jms-3.0.xsd"> 

<bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" 
p:brokerURL="tcp://localhost:61616" /> 

<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"> 
<constructor-arg name="connectionFactory" ref="connectionFactory"></constructor-arg> 
<property name="defaultDestinationName" value="myqueue"></property> 
</bean> 

<context:component-scan base-package="com.jms"></context:component-scan> 

</beans> 
Các vấn đề liên quan