Skip to content

Instantly share code, notes, and snippets.

public static WebApplicationContext getCurrentWebApplicationContext() {
return (WebApplicationContext) currentContextPerThread.get(Thread.currentThread().getContextClassLoader());
}
@zzzfree
zzzfree / gist:5060808
Last active December 14, 2015 08:49
appliation bean
import org.springframework.context.ApplicationContext
import org.springframework.context.support.FileSystemXmlApplicationContext
class BeanUtil {
ApplicationContext context=new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
static instance = new BeanUtil();
public Object get(Object s) {
在web.xml中配置
配置监听器:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener </listener-class>
</listener>
Jsp中处理:
<%
//第三种方式
ServletContext servletContext = request.getSession().getServletContext();
ApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext(servletContext);
@zzzfree
zzzfree / ImageResize.groovy
Last active December 14, 2015 15:09
ImageResize
import javax.swing.ImageIcon
import java.awt.Color
import java.awt.image.BufferedImage
import java.awt.image.ColorModel
import java.awt.image.WritableRaster
import java.awt.Graphics2D
import javax.imageio.*
import java.awt.*
@zzzfree
zzzfree / gist:5106203
Created March 7, 2013 07:27
MapQueue
class MapQueue {
def max=0
def last=0
def c = [:]
def q = []
def MapQueue(m){
max=m
}
@zzzfree
zzzfree / LuceneAdd.groovy
Last active December 14, 2015 16:18
Lucene Add
import org.apache.lucene.analysis.Analyzer
import org.apache.lucene.analysis.standard.StandardAnalyzer
import org.apache.lucene.document.Document
import org.apache.lucene.document.Field
import org.apache.lucene.document.LongField
import org.apache.lucene.document.StringField
import org.apache.lucene.document.TextField
import org.apache.lucene.index.IndexWriter
import org.apache.lucene.index.IndexWriterConfig
import org.apache.lucene.index.Term
@zzzfree
zzzfree / gist:5113763
Last active December 14, 2015 16:18
Lucene Search
// http://www.cnblogs.com/lcuzhanglei/archive/2012/08/01/2618381.html
// 对于要排序的字段,在索引的时候可以Field.Index.NOT_ANALYZED
import org.apache.lucene.analysis.Analyzer
import org.apache.lucene.analysis.standard.StandardAnalyzer
import org.apache.lucene.index.IndexReader
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.queryparser.classic.QueryParser
import org.apache.lucene.search.IndexSearcher
import org.apache.lucene.search.Query
@zzzfree
zzzfree / gist:5113873
Created March 8, 2013 02:52
Lucene search page
import org.apache.lucene.analysis.Analyzer
import org.apache.lucene.analysis.standard.StandardAnalyzer
import org.apache.lucene.index.IndexReader
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.queryparser.classic.QueryParser
import org.apache.lucene.search.IndexSearcher
import org.apache.lucene.search.Query
import org.apache.lucene.search.TopDocs
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
@zzzfree
zzzfree / gist:5114466
Created March 8, 2013 05:46
reflect groovy
class ReflectTest {
def name
def height
def add(){
println "add"
}
def add(a){