Tag Archives: Spring

Spring 4 framework + wildfly 20 log4j2 無法產生 log

解決這個問題需要做以下處理:

修改 wildfly logging 設定
Configuration > Subsystems > Logging > Configuration
將 Add Logging Api Dependencies 改為 false
maven pom 檔有以下 dependency

    <dependency>
    	<groupId>org.slf4j</groupId>
    	<artifactId>slf4j-api</artifactId>
    	<version>1.7.30</version>
    </dependency>
    <dependency>
    	<groupId>org.apache.logging.log4j</groupId>
    	<artifactId>log4j-core</artifactId>
    	<version>2.13.3</version>
    </dependency>
    <dependency>
    	<groupId>org.apache.logging.log4j</groupId>
    	<artifactId>log4j-api</artifactId>
    	<version>2.13.3</version>
    </dependency>
    <dependency>
    	<groupId>org.apache.logging.log4j</groupId>
    	<artifactId>log4j-slf4j-impl</artifactId>
    	<version>2.13.3</version>
    </dependency>
    <dependency>
    	<groupId>org.apache.logging.log4j</groupId>
    	<artifactId>log4j-jcl</artifactId>
    	<version>2.13.3</version>
    </dependency>
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

Spring framework transaction control (Programmatic)

在一些比較早期的專案可能 application server、framework、java runtime 的版本都比較舊或不允許做太大幅度的變動,這時候以程式來控制 transaction 變成唯一的選擇,本文主要參考這個 網址

首先在 applicationContext.xml 設定 transaction 相關物件

<bean id=”transactionManagerJDBC”
class=”org.springframework.jdbc.datasource.DataSourceTransactionManager”>
<property name=”dataSource” ref=”dataSource”></property>
</bean>

<bean id=”transactionTemplate” class=”org.springframework.transaction.support.TransactionTemplate”>
<property name=”transactionManager” ref=”transactionManagerJDBC”></property>
</bean>

<bean id=”jdbcTemplate” class=”org.springframework.jdbc.core.JdbcTemplate”>
<property name=”dataSource” ref=”dataSource”></property>
</bean>

接著將以上物件 inject 到需要 transaction contorl 的 java class,這部份就不再細述,transaction code example 如下

transactionTemplate.execute(new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
try {

// do you works here
} catch (Exception e) {
status.setRollbackOnly();
}
}
});

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...