顯示具有 configuration 標籤的文章。 顯示所有文章
顯示具有 configuration 標籤的文章。 顯示所有文章

2014年1月6日 星期一

[J2EE] web.xml

/WEB-INF/web.xml

The deployment descriptor file describes how to deploy a web application in a servlet container such as Tomcat..


What are web.xml doing:
  • To determine how URLs map to servlets.
  • Which URLs require authentication.
  • Describes the classes, resources and configuration of the application and how the web server.


* Reference
- Web.xml
- The Deployment Descriptor: web.xml
- web.xml - DTD and XSD

2012年7月1日 星期日

[Apache] Directory setting

httpd.conf
Alias /virtualUrl /RealUrl


    AllowOverride None
    Options None
    Order allow,deny
    Allow from all


2012年5月6日 星期日

[Spring] configurations


<!-- Activates various annotations to be detected in bean classes -->
<!-- 設定註釋注册到Spring容器 -->
<context:annotation-config />

<!-- Scans the classpath for annotated components that will be auto-registered as Spring beans.
 For example @Controller and @Service. Make sure to set the correct base-package-->
<!-- 在 base-package下尋找有 @Component 和 @Configuration 的 target Class予註冊為 bean -->
<context:component-scan base-package="org.krams.tutorial" />

<!-- Configures the annotation-driven Spring MVC Controller programming model.
Note that, with Spring 3.0, this tag works in Servlet MVC only!  -->
<mvc:annotation-driven />


* Reference
- krams::: Spring 3 MVC: Using @ModelAttribute in Your JSPs

2011年10月1日 星期六

[Spring] mvc annotation

* mvc:annotation-driven
  • registers a DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter.
  • @NumberFormat and @DateTimeFormat annotations.
  • JSR-303 Bean Validation API support will be detected on classpath and enabled automatically.

* mvc:default-servlet-handler
  • allows for mapping the DispatcherServlet to "/" (thus overriding the mapping of the container's default Servlet),
  • while still allowing static resource requests to be handled by the container's default Servlet.


[Struts] action and jsp


    jsp file path

method: 指定要去執行的 method。

result: 是 action 裡指定要對應到頁面的字串。

2011年9月23日 星期五

[Apache] Set context root by MatchExPression

* Setting Apache context root (/conf/httpd.conf):

加入以下設定並填入該環境的 domain 和 port

MatchExpression /mobile WebLogicCluster={#domain}:{#port}|Debug=ON

[JPA] javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode

Error Message
nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)


Solution

weblogic  /bea/setDomainEnv.sh 未指定 JPA jar path


if [ "${SERVER_NAME}" = "managed01d-1" ] ; then
    PRE_CLASSPATH="${DOMAIN_HOME}/lib-ext/hibernate-jpa-2.0-api-1.0.0.Final.jar"
    export PRE_CLASSPATH
fi

2011年9月12日 星期一

[maven] build command

  • mvn [clean] package
  • mvn -o [clean] package
    • Offline Build.
  • mvn -Dbuild.stage=staging clean package
  • mvn -Dmaven.test.skip=false package
    • enable the unit testing.
  • mvn -Dmaven.test.skip=false test
    • testing only.
  • mvn -Dmaven.test.skip=true -Dbuild.stage=staging clean package

2011年4月18日 星期一

[Configuration] persistence.xml and applicationContext.xml

* How does the server know which database it is supposed to save / update / query the entity objects? How do we configure the underlying object-relational-mapping engine and cache for better performance and trouble shooting? The persistence.xml file gives you complete flexibility to configure the EntityManager.

* persistence.xml file
  • Is a standard configuration file in JPA.
  • Has to be included in the META-INF directory inside the JAR file that contains the entity beans.
  • The <provider> specifies the underlying implementation of the JPA EntityManager.
  • The <jta-data-source> points to the JNDI name of the database this persistence unit maps to.

* Since you might have multiple instances of persistence-unit defined in the same application, you typically need to explicitly tell the @PersistenceContext annotation which unit you want to inject. For instance, @PersistenceContext(name="myapp") injects the EntityManager from the persistence-unit named "myapp".

* JTA:
  • One of the Java Enterprise Edition (Java EE) APIs allowing distributed transactions to be done across multiple XA resources in a Java environment.
  • Provides for:
    • demarcation of transaction boundaries
    • X/Open XA API allowing resources to participate in transactions.

* <tx:annotation-driven>
  • Enabled spring to interpret @Transactional annotation.
  • Creates a BeanPostProcessor to be included in the BeanPostProcessor step in the initialization phase.
    • When that BeanPostProcessor sees @Transactional in your Spring bean code, then it create a DynamicProxy to proxy that bean so that it will run transactionally.

* 一個 LocalContainerEntityManagerFactoryBean 只能管理一個持久化單元, 僅管其内部創建的DefaultPersistenceUnitManager 類可以得取多個持久化單元信息(PersistenceUnitInfo), 但最终只能有一個被返回给 LocalContainerEntityManagerFactoryBean 用於創建 JPA 實現提供者的 EntityManagerFactory

* Entity Manager 藉由 Persistence Context 來控制被管理的 Entity Instances,而每個 Persistence Context 必定由一個 Persistence Unit 來限制該 Context 可以管理的 Entity Classes 種類。

* Entity Manager 可以分為兩類
  • Container-Managed Entity Manager
    • 是由 JEE Container 所管理的 Entity Manager
    • 主要是以 @PersistenceContext 標識在你的程式中,Container 會在執行期間自動注入對應的 instance。
    • 可以再區分兩類:
      • PersistenceContextType.TRANSACTION (Default):
        • 主要是配合 Stateless Session Bean 與 JTA Transaction,在每次 method 被呼叫時都去檢查 JTA transaction 中是不是有 Persistence Context,如果有就續用否則就建一個新的。
        • 當 JTA Transaction commit 時,在 persistence context 中的 entity instances 就會自動 persist 至 DB。
      • PersistenceContextType.EXTENDED:
        • 主要是配合 Stateful Session Bean,只有當執行到有 @Remove 標識的 method 時才會 persist 在 persistence context 中的 entity instances。
  • Application-Managed Entity Manager
    • Application 自行管理,藉由呼叫 EntityManagerFactory.createEntityManager() 來取得,因此,一般的 J2SE程式也可以使用,當然在 JEE Container 也可以使用,特別是在某些特別情況或有特殊考慮時多一種方式可以應用。
    • 如果要在 JEE Container 中使用的話,與 Container-Managed Entity Manager 不同之處是以 @PersistenceUnit 來標識要被注入的 EntityManagerFactory,而且也必需呼叫 EntityManager.close() 來指出要 persist 的時機。
    • 產生 persistence context 的時機也有所不同,當呼叫 EntityManagerFactory.createEntityManager() 就會產生一個 persistence context。

* JPA allows us to work with entity classes, which are denoted as such using
  • The annotation @Entity.
  • configured in an XML file (we'll call this persistence meta information).
When we acquire the Entity Manager Factory using the Persistence class, the Entity Manager Factory finds and processes the persistence meta information.


* To work with a database using JPA, we need an Entity Manager. Before we can do that, we need to create an Entity Manager Factory.
=> Entity Manager Factory -> Entity Manager -> using JPA...

* To acquire an Entity Manager Factory, we use the class javax.persistence.Persistence.
  • It reads a file called persistence.xml in the META-INF directory.
  • Then creates the named Entity Manager Factory, which processes persistence meta information stored in XML files or annotations (we only use annotations).

* Once we have an Entity Manager, we can ask it to perform several operations such as persisting or removing an entity from the database or creating a query.



* Reference
- 1.2.1. The persistence.xml file
- Java Transaction API
- Understanding working
- 非J2EE 容器环境下Spring +JPA 多持久化单元/多个JAR归档注解实体 的实体扫描问题及解决办法
- JPA2--Transaction Management
- Comments/Suggestions, please email: schuchert -at- yahoo -dot- com

2011年4月10日 星期日

[Configuration] log4j.xml

* 有 property and xml 兩種設定方式

* Log level
FATAL      0  
  ERROR      3  
  WARN       4  
  INFO       6  
  DEBUG      7 

* Appender: log 輸出位置
org.apache.log4j.ConsoleAppender: 控制台

org.apache.log4j.FileAppender: 文件
 - . Threshold: log 最低 levle
. ImmediateFlush: default is true, 所有 log 都會馬上被 output
. Target: default is System.out, output on console,
   to choose which console stream to print messages to, System.out or System.err.

org.apache.log4j.DailyRollingFileAppender: 每天產生一個 log file
- . Append: default is true, 將 log 增加到指定 file, false is 覆蓋 log
. File: 指定文件
......

org.apache.log4j.RollingFileAppender: 文件大小到達指定大小的时候產生一個新的文件

org.apache.log4j.WriterAppender: 將 log 信息以串流格式發送到任意指定的地方

* Layout: log 輸出格式
org.apache.log4j.HTMLLayout: 以HTML表格形式布局

org.apache.log4j.PatternLayout: 可任意自定格式

org.apache.log4j.SimpleLayout: 包含 log 信息的级别和信息字符串

org.apache.log4j.TTCCLayout: 包含產生 log 的時間、thread、class 等等信息

* 列印參數的格式類似於 C
%m   程式中的 message

  %p   log level

  %r   啟動應用到輸出 log 所花費的毫秒數

  %c   class name

  %t   產生該 log 的 thread

  %n   換行

  %d   日期或時間,ex: %d{yyy MMM dd HH:mm:ss , SSS}

  %l   log 的發生位置,包括 class name, thread, line number,ex: Testlog4.main(TestLog4.java: 10 )。

* Logger: 對應 package 和 appender
additivity: 是否往上查找未設定的屬性
appender-ref: appender reference,可以有多個
level: log level priority,default is "debug"
  //  若沒有設定則是繼承 root logger 的設定
  // everything of spring log level is default "info"

* root: root Logger
以 root 的 LEVEL 為主,ex: 假設 root level 為 INFO,那麼即使設為 DEBUG 也只會輸出到 INFO level。

* API
  • PatternLayout
    • The goal of this class is to format a LoggingEvent and return the results as a String. The results depend on the conversion pattern.
    • The left justification flag which is just the minus (-) character comes the optional minimum field width modifier. This is a decimal constant that represents the minimum number of characters to output.
    • The padding character is space. If the data item is larger than the minimum field width, the field is expanded to accommodate the data. The value is never truncated.
    • This behavior can be changed using the maximum field width modifier which is designated by a period followed by a decimal constant. If the data item is longer than the maximum field, then the extra characters are removed from the beginning of the data item and not from the end.
  • ConsoleAppender
    • Appends log events to System.out or System.err using a layout specified by the user. The default target is System.out.
  • LevelRangeFilter
    • A very simple filter based on level matching, which can be used to reject messages with priorities outside a certain range.
    • The filter admits three options LevelMin, LevelMax and AcceptOnMatch.
    • If LevelMinw/LevelMax is not defined, then there is no minimum/maximum acceptable level (ie a level is never rejected for being too "low"/unimportant// "high"/important).
  • DailyRollingFileAppender
    • The rolling schedule is specified by the DatePattern option. This pattern should follow the SimpleDateFormat conventions. In particular, you must escape literal text within a pair of single quotes. A formatted version of the date pattern is used as the suffix for the rolled file name.
  • Logger
  • Level
    • Defines the minimum set of levels recognized by the system, that is OFFFATALERRORWARNINFODEBUG and ALL.
    • TRACE: The TRACE Level designates finer-grained informational events than the DEBUG

* Reference
- log4j 基本配置
- Apache Log4j 1.2.16 API
- log4j使用指南 ***
- Apache Log4j 学习笔记 **
- org.apache.log4j.Logger 详解 **
- wiki

2011年4月7日 星期四

[Configuration] pom.xml

* Project Object Model (POM)
  • The fundamental unit of work in Maven.
  • An XML file that contains information about the project and configuration details used by Maven to build the project.
  • Contains default values for most projects, ex: the build directory, which is target; the source directory, which is src/main/java; the test source directory, which is src/main/test; and so on.

* 在 Maven 中,有三個內建的建構生命週期:
  • Default: 處理專案部署。
  • Clean: 處理專案資源清除。
  • Site: 處理專案文件。

* 使用 mvn 指令呼叫執行某個階段,都是呼叫某個 plugin 來執行,像是編譯時會使用 mvn compile,這會呼叫 Maven 的 maven-compiler-plugin,這個 plugin 在 Super POM 中會有預設值。

* plugin
  • maven-resources-plugin: 處理專案資源的複製。
  • maven-compiler-plugin: 負責專案的編譯。
  • maven-surefire-plugin: 負責專案的單元測試。
  • maven-jar-plugin: 負責專案的包裝。
  • maven-clean-plugin
    • Will delete the target directory by default. You may configure it to delete additional directories and files.
    • The directory in the fileset is a relative path inside a project,


* 可有以下關係
  • 繼承
  •   
          
           目前使用的 POM 版本
           組織或項目的唯一標誌,會成為預設的套件名稱  
           項目的通用名稱,這將成為你存放製品的資料夾名稱,通常就是專案名稱  
           產品版本  
           打包出來的檔案類別, ex: war, jar...  
      
    
  • 依賴
  •   
          
          組織或項目的唯一標誌  
          項目的通用名稱  
          版本  
          檔案類型 (war, jar...)  
          用於限制相應的依賴範圍,ex: compile, runtime...  
          用於連續依賴時  
          
        ...  
        
    
  • 合成

* Build
  
   
      打包後的檔案名稱
        
      打包檔案目錄  
        
        
            
        
      

        
            
              資源所在位置  
            
          
    


* Reference
- Introduction to the POM
- 我的Maven2之旅:五.pom.xml基本元素介绍
- maven 配置篇 之pom.xml(一) **
- JUnit Gossip: 使用 Maven
- JUnit Gossip: POM 設定檔
- JUnit Gossip: 建構生命週期
- Maven Clean plugin - Delete Additional Files Not Exposed to Maven

2011年4月6日 星期三

[Configuration] web.xml

* 以下會影響正確性
  • 大小寫
  • 元素順序,ex: servlet元素必須出現在所有servlet-mapping元素之前。

* 元素配置


    
    










    



    
    
    
        




    
    




    
























* Reference
- Tomcat中用web.xml控制Web应用详解(1)
- web.xml元素:常见设定值一览 **