AdSense

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

2025/3/5

Java Spring Fortify Path Manipulation by injected properties

Fortify弱點掃描出現Path Manipulation(路徑操縱)問題的解決方式如下。

2024/8/20

Java web.xml context-param contextConfigLocation用途

Java Web應用程式中web.xml內的<context-param>的contextConfigLocation作用如下。

2024/8/19

2021/4/26

Spring Boot 使用@Lookup取得prototype bean

Spring IoC管理的bean預設scope為singleton。若bean為有狀態(stateful)時應設為prototype才能使每一次產生的bean實例不同。而當singleton bean要取得依賴的prototype bean的實例時,可使用@Lookup annotation來取得不同的prototype bean的實例。

2021/1/12

Spring Boot Data JPA PlatformTransactionManager 手動管理交易

Spring Boot Data JPA使用PlatformTransactionManager在程式中手動管理交易。

2020/12/16

Spring JdbcTemplate query BeanPropertyRowMapper return List elements are null

今天同事和我分享關於BeanPropertyRowMapper回傳List<String>長度大於零但內容為空的現象。

2020/11/24

Spring org.springframework.mail.MailSendException: Failed messages: javax.mail.internet.AddressException: Empty address in string ``''

今天使用Spring JavaMailSender發送email通知信時出現錯誤;
org.springframework.mail.MailSendException: Failed messages: javax.mail.internet.AddressException: Empty address in string ``''。

2020/10/21

Spring 呼叫同類別的@Transactional方法不會回滾 call same class @Transactional method no rollback

Spring的交易管理(中國叫做事務管理)(Transactoinal Management)中,當由同類別中一個無交易管理(無@Transactional)的方法呼叫另一個有交易管理(有@Transactional)的方法時,有交易管理的方法發生例外時資料不會回滾(rollback)。

2020/9/27

Spring Boot @PropertySource 依 spring.profiles.active載入對應的properties

Spring可在application.properties設定spring.profiles.active的值來切換不同環境用的application配置檔。而application外的自訂配置檔透過@PropertySource載入時也要依spring.profiles.active載入對應的配置檔的設定如下。

2020/9/24

Spring Boot @ConfigurationProperties with @ConstructorBinding

Spring使用@ConfigurationProperties及@ConstructorBinding將properties檔內容以建構式注入到bean。

Spring Boot 使用@ConfigurationProperties 綁定properties至Bean

Spring除了能使用@Value把properties配置設定值注入到成員變數中外,也可透過@ConfigurationProperties將properties檔內容綁定到Bean類的屬性。

2020/9/19

Spring Boot @ComponentScan掃描指定套件(包) scan specific package

在SpringBoot專案通常都直接把類別放在@SpringBootApplication類所在package下的package,然後Spring預設會掃描這些package並把掛有@Compoment、@Repository、@Service、@Controller、@Configuration的類別註冊為Spring bean。

不過如果專案package及類別非常多會造成啟動時很慢,因為要花很多時間去掃描這些package。要改善此情況可設定只掃描特定的package來提高掃描註冊bean的效率。

2020/9/17

Spring Boot 使用@Schedule建立排程任務範例

Spring Boot使用@Schedule排程(scheduling task)簡單範例如下。

Spring Boot 操控台印出彩色文字 console log ANSI color output

Spring Boot預設在IDE(IntelliJ IDEA or Eclipse)印出的日誌訊息都是單色的,但透過設定以下參數即可在操控台(console)印出彩色日誌。

2020/8/29

Spring @Transactional 屬性預設值 attributes default setting

Spring @Transactional的屬性值預設如下。

Spring @Transactional 標註在類別的效果

Spring處理交易管理的@Transactional注釋可標註在類別(class)或方法(method)前,標注在類別的效果如下。

AdSense