วันเสาร์ที่ 16 กรกฎาคม พ.ศ. 2559

การ Config SpringBoot ให้ใช้งานแบบมี web.xml

การ Config แบบนี้จะต้องย้ายพวก filter ออกมาจาก annotation แล้วมา config บน web.xml ให้หมดด้วยครับ ไม่งั้นจะใช้งานไม่ได้ ใน web.xml ผมมีตัวอย่างของการ Config CXF ด้วย ว่าต้องย้ายมาไว้บน web.xml ด้วยไม่งั้นใช้งานไม่ได้
<context-param>
 <param-name>contextConfigLocation</param-name>
 <param-value>xxx.Application</param-value>
</context-param>

<listener>
 <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
</listener>

<servlet>
 <servlet-name>spring</servlet-name>
 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 <init-param>
  <param-name>contextAttribute</param-name>
  <param-value>org.springframework.web.context.WebApplicationContext.ROOT
  </param-value>
 </init-param>
 <load-on-startup>1</load-on-startup>
</servlet>

<!-- Servlet Mapping for CXFServlet -->
<servlet>
 <servlet-name>CXFServlet</servlet-name>
 <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
</servlet>

<servlet-mapping>
 <servlet-name>CXFServlet</servlet-name>
 <url-pattern>/soap-api/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
 <servlet-name>spring</servlet-name>
 <url-pattern>/*</url-pattern>
</servlet-mapping>
- จะเห็นว่าใช้ org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener ตัวนี้แทนของเดิม
- contextConfigLocation เพื่อไปอ่าน Class ที่ Config ของ  SpringBoot เหมือนกับที่ต้อง config บน start-class ที่ใช้บน maven เพื่อให้มันทำานได้

Related Posts:

  • Config Maven สำหรับ Websphereเป็นการ Config Eclipse เพิ่มเติมสำหรับ Add Reference Websphere  ครับ โดยเพิ่ม ข้อมูลตามนี้ แยกตามแต่ละชนิดของ Application (ในส่วน additionalProje… Read More
  • การ Config SpringBoot ให้ใช้งานแบบมี web.xmlการ Config แบบนี้จะต้องย้ายพวก filter ออกมาจาก annotation แล้วมา config บน web.xml ให้หมดด้วยครับ ไม่งั้นจะใช้งานไม่ได้ ใน web.xml ผมมีตัวอย่างของการ … Read More
  • Config Maven ให้โหลด Source และ API Docsปกติสามารถโหลดได้จาก Command Line ได้เลยครับ หรือจะไป Config บน settings.xml 1. แบบที่ทำผ่าน Command Line ให้เพิ่ม -DdownloadSources=true -Ddownload… Read More
  • Config Maven ให้ eclipse มองเห็นเป็น Dynamic Web Project โดยปกติ ตอนสร้าง เราจะใช้ -DarchetypeArtifactId=maven-archetype-webapp ในการสร้าง dynamic project แต่พอเราสร้างให้ใช้กับ eclipse แล้ว eclipse จะมอง… Read More
  • การสร้าง jax-ws บน Tomcatผมเขียนโดยใช้ maven ในการสร้าง Project น่ะครับ และทำให้รันบน Tomcat ถ้าบน Application Server ใช้ Config น้อยกว่านี้น่ะครับ1. เพิ่ม Config ใน Maven เข้… Read More