Sam的程式筆記

  • About Me
  • Archive
  • feeds

Posts match “ spring ” tag:

over 9 years ago

Spring與Jackson結合

要讓Spring自動幫你轉成Json格式有很多方法,目前採用Jackson2解決方式

Read on →
  • spring
  • json
  • October 01, 2013 17:16
  • Permalink
  • Comments
 
over 9 years ago

spring內設定檔加密

在spring內設定資料庫參數時只能放明碼,這在很多時候是不被允許的,所以要改成加密方式儲存在設定檔

Read on →
  • spring
  • config
  • encrypt
  • October 03, 2013 18:11
  • Permalink
  • Comments
 
over 9 years ago

自訂json欄位過濾器

在結合Spring跟jackson之後,幾乎所有的物件幾乎都可以自動幫你變成json資料格式輸出,
雖然有@JsonIgnore可以註解掉某些不想輸出的欄位,但有的時候需要有的時候不需要的話就要靠自訂過濾器來輔助了

Read on →
  • spring
  • json
  • filter
  • October 04, 2013 13:48
  • Permalink
  • Comments
 
over 9 years ago

Spring與log4j

整合spring跟log4j很方便

Read on →
  • spring
  • log4j
  • October 11, 2013 11:39
  • Permalink
  • Comments
 
almost 9 years ago

Use Jasypt Encryptor Configuration In Spring

官方網站:http://www.jasypt.org/

你原本設定檔可能是明碼長這樣

database.driverClassName=com.mysql.jdbc.Driver
database.url=jdbc\:mysql\://localhost\:3306/test?autoReconnect\=true&useUnicode\=true&characterEncoding\=UTF-8&zeroDateTimeBehavior\=convertToNull
database.username=root
database.password=1qaz2wsx
Read on →
  • spring
  • encryptor
  • March 14, 2014 15:47
  • Permalink
  • Comments
 
over 8 years ago

使用Maven管理WEB專案套件

最近要來玩玩看Spring4的時候發現找不到下載點,因為Spring已經把Maven作為主要的提供方式了,
好吧,那你就只好學吧

1.準備軟體

Eclipse IDE for Java EE Developers下載 : http://maven.apache.org/
Maven 3.2.1 (Binary zip) 下載 : http://maven.apache.org/download.cgi
Maven解壓縮後我是放在D:\IDE\maven

Read on →
  • spring
  • maven
  • May 13, 2014 18:43
  • Permalink
  • Comments
 
over 8 years ago

Spring中使用多國語系

在Spring設定檔中

application-beans.xml
<!-- 多國語言支持 -->
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
  <property name="basenames">
    <list>
      <value>classpath:i18n/messages</value>
    </list>
  </property>
  <property name="defaultEncoding" value="UTF-8" />
  <property name="cacheSeconds" value="1800" />
</bean>
<!-- 輔助類別,幫助在非spring管理下的物件取得spring管理的物件 -->
<bean id="SpringApplicationContext" class="com.secom.mobile.common.ApplicationContextHelper"></bean>
Read on →
  • spring
  • i18n
  • August 04, 2014 20:53
  • Permalink
  • Comments
 
over 8 years ago

Spring 注入 List Map 方法

在設定檔中這樣寫

config.properties
article.fileexts.allow.of.strings=jpg,jpeg,gif,png,tif,bmp,pdf

在Spring中可以使用這樣自動注入成List

java
@Value("#{'${article.fileexts.allow.of.strings}'.split(',')}") 
private List<String> fileextsallow;

============================================================================================
如果需要的是Map比較複雜的類型要透過xml表達

application-beans.xml
<util:map id="englishStrings" key-type="java.lang.String" value-type="java.lang.String">
         <entry key="A" value="Test 1"/>
</util:map>

接著指定資源名稱即可取得

java
@Resource(name="englishStrings")
private Map<String,String> englishStrings1;
Read on →
  • spring
  • August 06, 2014 19:30
  • Permalink
  • Comments
 
over 8 years ago

Spring客製化載入設定檔

有些設定檔比如說像是加解密金鑰會需要在載入設定檔的時候就做好處理
透過PropertyPlaceholderConfigurer來達成

Read on →
  • spring
  • August 11, 2014 20:47
  • Permalink
  • Comments
 
over 8 years ago

在非Spring管理下想取得Spring管理的Bean

有時需求必須額外開Thread,但並不是用Spring管理的方式,但卻也想取得原來原本就做好的類別
透過ApplicationContextAware來達成此需求

Read on →
  • spring
  • ApplicationContextAware
  • August 12, 2014 09:59
  • Permalink
  • Comments
 
about 8 years ago

使用Spring AOP機制插入紀錄點

有的時候會有特別需求要紀錄資料進入、出去以及是否執行成功,原則上是直接寫log就好,或是你需要一個統一而且不需要動到原本程式的話,使用AOP機制會是一個好方法。

Read on →
  • spring
  • aop
  • November 20, 2014 16:18
  • Permalink
  • Comments
 
about 8 years ago

Quartz排程透過Spring執行一般Bean方法

排程在專案中常常會需要使用到,但是一般排程他是透過其他的Thread來計時跟控管,所以你沒辦法拿到Spring中既有的資源,你的排程程式也必須繼承Job,所以排程這隻就只能for排程使用了。

但是如果你透過下面方式來設定,你的程式就可以不用繼承Job,又可取得Spring的資源,開發上會省事點

Read on →
  • Quartz
  • spring
  • December 15, 2014 14:44
  • Permalink
  • Comments
 
over 7 years ago

Spring BCryptPasswordEncoder

build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.springframework.security:spring-security-core:4.0.1.RELEASE'
}
Test1.java
package com.sam.test;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class Test1 {

    public static void main(String[] args) {
        int i = 0;
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        while (i < 10) {
            String password = "123456";
            
            String hashedPassword = passwordEncoder.encode(password);
     
            System.out.println(hashedPassword);
            i++;
        }
        
        System.out.println(passwordEncoder.matches("123456ergnesiougsefwewfwer34Tt1", "$2a$10$Ja8bUpc2cacAB0EvXcj1JO2i4PgGWWvxaQ.FSZ.prQdCkEFEQNNBi"));
    }
}
$2a$10$RjV.cEW29EGHXZZfFNoQFOz/J.PVVvkc2MWdUv1XQQhwWUfDSw7fa
$2a$10$pPKzHES6BE6YV9pqZwpaeeZEpA7jf24WWUdctXpmyzyk7z4kBh.2S
$2a$10$F9sRVVH90yRtnjJeC28HQOtWMDwqD1FqQ/Lhjf4UGRmVVA7HoJjxK
$2a$10$Dst6SnEdB2g1L9o0LfJoQ.Y8XwKoaKkoSkGNMxKsOaRRdHvB5yysy
$2a$10$igeXt7sS7jguvQBl4ILzy.DICtQa6zkdGiCp9u/lQ2KDv/wPU9E7W
$2a$10$lD00aUWxJG/Xiq5bMHdhZOHbaEHKpYAAs8k847Q0Vq7nQVNX1pRu.
$2a$10$fgLEGoiVPIKXw8h2qYtUp.UrcQawvXYZDEEj1AUwORUNFu70i5il.
$2a$10$d4nNA9OSjfPWvaKsDScxAuwBlUpX909fY1/Pwq7lsZhZ0Vx/DZF4W
$2a$10$hgQqIohovnGbA.UbIzom8OanIHyrA3lMRH3JMQcO.3saJ5XMujRl.
$2a$10$c85hYXPx4niZCCkmxeqXHOriQvvaWBSd9SVpYoq2ZAbs0uUa1ESL.
false
  • spring
  • Security
  • BCryptPasswordEncoder
  • July 17, 2015 17:41
  • Permalink
  • Comments
 
over 7 years ago

Spring Boot Schedule

以前設定固定排程最常用就是 Quartz 但是難免還要配置一些東西,現在用 Spring-boot 只要一個註解就可以啟動排程工作了

Read on →
  • spring
  • SpringBoot
  • Schedule
  • September 10, 2015 18:38
  • Permalink
  • Comments
 
over 7 years ago

使用Spring-Boot整合Spring-Data操作ElasticSearch

讓操作 NoSQL 像 ORM 般簡單,這邊是用 Elasticsearch 當儲存,並用 jsoup 來爬文

http://docs.spring.io/spring-data/elasticsearch/docs/current/reference/html/

Read on →
  • spring
  • boot
  • data
  • ElasticSearch
  • July 21, 2015 18:25
  • Permalink
  • Comments
 
almost 6 years ago

spring-retry 使用方式

spring-retry 非常的好用,可以基於 Exception 來判斷要不要重試,所以遇上網路不穩的環境時就可以省力許多

Read on →
  • Spring
  • Retry
  • February 22, 2017 17:49
  • Permalink
  • Comments
 
about 5 years ago

How to use Spring Cloud Contract perform end-to-end tests

消費者驅動的契約測試(Consumer-Driven Contracts,簡稱CDC),是指從消費者業務實現的角度出發,驅動出契約,再基於契約,對提供者驗證的一種測試方式。

Read on →
  • spring
  • cloud
  • contract
  • CDC
  • end-to-end tests
  • Consumer-Driven Contracts
  • November 08, 2017 15:00
  • Permalink
  • Comments
 

Copyright © 2013 samchu . Powered by Logdown.
Based on work at subtlepatterns.com.