13. mongoDB
public class MongoTemplate {
private static DB db;
private static MongoClient mongoClient;
public MongoTemplate(String dbName, String username, String password,
String host, int port, boolean autoConnectRetry,
int connectionsPerHost, int connectTimeout,
int maxWaitTime, int threadsAllowedToBlockForConnectionMultiplier,
int socketTimeout) {
if(mongoClient == null){
Builder b = MongoClientOptions.builder();
b.autoConnectRetry(autoConnectRetry);
b.connectionsPerHost(connectionsPerHost);
b.connectTimeout(connectTimeout);
b.maxWaitTime(maxWaitTime);
b.threadsAllowedToBlockForConnectionMultiplier(threadsAllowedToBlockForConnectionMultiplier);
b.socketTimeout(socketTimeout);
MongoClientOptions options = b.build();
try {
List<ServerAddress> list = new ArrayList<ServerAddress>();
for(String h : host.split(";")){
list.add(new ServerAddress(h.split(":")[0], Integer.parseInt(h.split(":")[1])));
}
mongoClient = new MongoClient(list,options);
mongoClient.setWriteConcern(WriteConcern.SAFE);
db = mongoClient.getDB(dbName);
db.authenticate(username, password.toCharArray());
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static DBCollection getDBCollection(String collectionName){
return db.getCollection(collectionName);
}
}
13년 9월 8일 일요일
14. cache - infinispan
@Configuration
@EnableCaching
public class InfinispanConfig {
@Bean
public SpringRemoteCacheManagerFactoryBean cacheManager() throws Exception{
SpringRemoteCacheManagerFactoryBean cacheManager = new SpringRemoteCacheManagerFactoryBean();
String active = System.getProperty("spring.profiles.active", "local");
cacheManager.setConfigurationPropertiesFileLocation(
new DefaultResourceLoader().getResource("classpath:hotrod-client-"+active+".properties")
);
return cacheManager;
}
} @Autowired CacheManager cacheManager;
@Test
public void test() throws Exception {
//obtain a handle to the remote default cache
Cache cache = cacheManager.getCache("default");
//now add something to the cache and make sure it is there
cache.put("car", "ferrari");
assert cache.get("car").get().equals("ferrari");
cache.evict("car");
assert cache.get("car").equals(null);
}
https://docs.jboss.org/author/display/ISPN/Using+Infinispan+as+a+Spring+Cache+provider
13년 9월 8일 일요일
15. cache - infinispan
✓ @Cacheable
✓ @CachePut
✓ @CacheEvict
@Cacheable(value = "authCache", key = "#key")
public DBObject getAuthInfo(String key) throws Exception
@CachePut(value = "authCache", key = "#key")
public DBObject generateAuthInfo(String key) throws Exception
@CacheEvict(value = "authCache", key = "#key")
public void removeAuthInfo(String key) throws Exception
13년 9월 8일 일요일
16. sitemesh@Override
protected Filter[] getServletFilters() {
CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
characterEncodingFilter.setEncoding("UTF-8");
characterEncodingFilter.setForceEncoding(true);
return new Filter[] { characterEncodingFilter, new SiteMeshFilter()};
}
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/WEB-INF/decorators/">
<excludes>
<pattern>/rss/*</pattern>
<pattern>/test/*</pattern>
<pattern>*.json</pattern>
</excludes>
<decorator name="default" page="mobileLayout.jsp">
<pattern>/</pattern>
</decorator>
<decorator name="mobile" page="webLayout.jsp">
<pattern>*.m</pattern>
</decorator>
<decorator name="app" page="appLayout.jsp">
<pattern>*.app</pattern>
</decorator>
</decorators>
13년 9월 8일 일요일
17. Thank You !
Q & A
www.playfam.com
unlogicaldev@gmail.com
https://github.com/unlogicaldev/springServlet3JavaConfig
13년 9월 8일 일요일