| | |
| | | import org.mybatis.spring.annotation.MapperScan; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| | | import org.springframework.boot.web.servlet.ServletComponentScan; |
| | | import springfox.documentation.swagger2.annotations.EnableSwagger2; |
| | | |
| | | /** |
| | | * LandApplication |
| | | * @author |
| | | */ |
| | | @SpringBootApplication(scanBasePackages={"com.lf.server.controller", "com.lf.server.service"}) |
| | | @EnableSwagger2 |
| | | @SpringBootApplication(scanBasePackages={"com.lf.server.config", "com.lf.server.mapper", "com.lf.server.service","com.lf.server.controller"}) |
| | | public class LfApplication { |
| | | public static void main(String[] args) { |
| | | SpringApplication.run(LfApplication.class, args); |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.config; |
| | | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * 屿§é
置类 |
| | | * @author WWW |
| | | */ |
| | | @Component |
| | | public class PropertiesConfig { |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.config; |
| | | |
| | | import com.fasterxml.jackson.annotation.JsonAutoDetect; |
| | | import com.fasterxml.jackson.annotation.PropertyAccessor; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.springframework.boot.autoconfigure.AutoConfigureAfter; |
| | | import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration; |
| | | import org.springframework.cache.Cache; |
| | | import org.springframework.cache.annotation.CachingConfigurerSupport; |
| | | import org.springframework.cache.interceptor.CacheErrorHandler; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.data.redis.connection.RedisConnectionFactory; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; |
| | | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * RedisConfig |
| | | * @author WWW |
| | | */ |
| | | @Configuration |
| | | @AutoConfigureAfter(RedisAutoConfiguration.class) |
| | | public class RedisConfig extends CachingConfigurerSupport { |
| | | /** |
| | | * é
ç½®èªå®ä¹redisTemplate |
| | | */ |
| | | @SuppressWarnings("deprecation") |
| | | @Bean |
| | | public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { |
| | | RedisTemplate<String, Object> template = new RedisTemplate<>(); |
| | | template.setConnectionFactory(redisConnectionFactory); |
| | | |
| | | // 使ç¨Jackson2JsonRedisSerializeræ¥åºåååååºååredisçvalueå¼ |
| | | Jackson2JsonRedisSerializer<Object> serializer = new Jackson2JsonRedisSerializer<Object>(Object.class); |
| | | |
| | | ObjectMapper mapper = new ObjectMapper(); |
| | | mapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); |
| | | mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); |
| | | serializer.setObjectMapper(mapper); |
| | | |
| | | template.setValueSerializer(serializer); |
| | | |
| | | //使ç¨StringRedisSerializeræ¥åºåååååºååredisçkeyå¼ |
| | | template.setKeySerializer(new StringRedisSerializer()); |
| | | template.setHashKeySerializer(new StringRedisSerializer()); |
| | | template.setHashValueSerializer(serializer); |
| | | template.afterPropertiesSet(); |
| | | |
| | | return template; |
| | | } |
| | | |
| | | @Bean |
| | | @Override |
| | | public CacheErrorHandler errorHandler() { |
| | | // å¼å¸¸å¤çï¼å½Redisåçå¼å¸¸æ¶ï¼æå°æ¥å¿ï¼ä½æ¯ç¨åºæ£å¸¸èµ° |
| | | return new CacheErrorHandler() { |
| | | @Override |
| | | public void handleCacheGetError(RuntimeException e, Cache cache, Object key) { |
| | | Map<String, Object> error = new HashMap<String, Object>(3); |
| | | error.put("e", e); |
| | | error.put("cache", cache); |
| | | error.put("key", key); |
| | | } |
| | | |
| | | @Override |
| | | public void handleCachePutError(RuntimeException e, Cache cache, Object key, Object value) { |
| | | Map<String, Object> error = new HashMap<String, Object>(4); |
| | | error.put("e", e); |
| | | error.put("cache", cache); |
| | | error.put("key", key); |
| | | error.put("value", value); |
| | | } |
| | | |
| | | @Override |
| | | public void handleCacheEvictError(RuntimeException e, Cache cache, Object key) { |
| | | Map<String, Object> error = new HashMap<String, Object>(3); |
| | | error.put("e", e); |
| | | error.put("cache", cache); |
| | | error.put("key", key); |
| | | } |
| | | |
| | | @Override |
| | | public void handleCacheClearError(RuntimeException e, Cache cache) { |
| | | Map<String, Object> error = new HashMap<String, Object>(2); |
| | | error.put("e", e); |
| | | error.put("cache", cache); |
| | | } |
| | | }; |
| | | } |
| | | } |
| | |
| | | import com.alibaba.fastjson.serializer.SerializerFeature; |
| | | import com.alibaba.fastjson.support.config.FastJsonConfig; |
| | | import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.http.MediaType; |
| | | import org.springframework.http.converter.HttpMessageConverter; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.AntPathMatcher; |
| | | import org.springframework.web.servlet.config.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.nio.charset.Charset; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * WebConfig |
| | | * @author WWW |
| | | */ |
| | | @Configuration |
| | | @Component |
| | | public class WebConfig extends WebMvcConfigurationSupport { |
| | | /** |
| | | * swaggeræ§å¶ |
| | |
| | | @Override |
| | | protected void addCorsMappings(CorsRegistry registry) { |
| | | registry.addMapping("/**") |
| | | .allowCredentials(true) |
| | | .allowedOrigins("*") |
| | | .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS") |
| | | .allowedHeaders("*") |
| | | .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") |
| | | .maxAge(3600) |
| | | .allowCredentials(true); |
| | | .maxAge(3600); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public void configureMessageConverters(List<HttpMessageConverter<?>> converters) { |
| | | FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); |
| | | FastJsonConfig fastJsonConfig = new FastJsonConfig(); |
| | | fastJsonConfig.setSerializerFeatures( |
| | | FastJsonConfig config = new FastJsonConfig(); |
| | | config.setSerializerFeatures( |
| | | SerializerFeature.WriteNullListAsEmpty, |
| | | SerializerFeature.WriteMapNullValue, |
| | | SerializerFeature.WriteNullStringAsEmpty, |
| | | //SerializerFeature.WriteNullStringAsEmpty, |
| | | SerializerFeature.WriteNullNumberAsZero, |
| | | SerializerFeature.WriteNullBooleanAsFalse); |
| | | // ç»ææ¯å¦æ ¼å¼å,é»è®¤ä¸ºfalse |
| | | //SerializerFeature.PrettyFormat); |
| | | |
| | | List<MediaType> fastMediaTypes = new ArrayList<>(); |
| | | converter.setSupportedMediaTypes(fastMediaTypes); |
| | | |
| | | converter.setFastJsonConfig(fastJsonConfig); |
| | | converter.setFastJsonConfig(config); |
| | | converter.setDefaultCharset(Charset.forName("UTF-8")); |
| | | converters.add(converter); |
| | | } |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.lf.server.config; |
| | | |
| | | public class WebMvcConfigurer { |
| | | } |
| | |
| | | package com.lf.server.interceptor; |
| | | |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.servlet.*; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.IOException; |
| | | |
| | | |
| | | /** |
| | | * è·¨åè¿æ»¤ |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException { |
| | | HttpServletResponse response = (HttpServletResponse) resp; |
| | | public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { |
| | | HttpServletResponse response = (HttpServletResponse) res; |
| | | HttpServletRequest request = (HttpServletRequest) req; |
| | | if (OPTIONS.equalsIgnoreCase(request.getMethod())) { |
| | | response.setHeader("Access-Control-Allow-Origin", "*"); |
| | | response.setHeader("Access-Control-Allow-Credentials", "true"); |
| | | response.setHeader("Access-Control-Allow-Methods", "GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS"); |
| | | response.setHeader("Access-Control-Max-Age", "86400"); |
| | | response.setHeader("Access-Control-Max-Age", "3600"); |
| | | response.setHeader("Access-Control-Allow-Headers", "*"); |
| | | |
| | | response.setStatus(HttpServletResponse.SC_OK); |
| | | } else { |
| | | chain.doFilter(req, resp); |
| | | chain.doFilter(req, res); |
| | | } |
| | | } |
| | | |
| | |
| | | server: |
| | | tomcat: |
| | | uri-encoding: UTF-8 |
| | | max-threads: 1000 |
| | | min-spare-threads: 5 |
| | | port: 12316 |
| | | context-path: /land |
| | | |
| | |
| | | url : jdbc:postgresql://192.168.20.39:5433/langfang |
| | | driver-class-name: org.postgresql.Driver |
| | | type: com.alibaba.druid.pool.DruidDataSource # èªå®ä¹æ°æ®æº |
| | | #url : jdbc:postgresql://127.0.0.1:5433/postgres |
| | | #Spring Boot é»è®¤æ¯ä¸æ³¨å
¥è¿äºå±æ§å¼çï¼éè¦èªå·±ç»å® |
| | | #druid æ°æ®æºä¸æé
ç½® |
| | | initialSize: 5 |
| | | minIdle: 5 |
| | |
| | | testOnBorrow: false |
| | | testOnReturn: false |
| | | poolPreparedStatements: true |
| | | |
| | | #é
ç½®çæ§ç»è®¡æ¦æªçfiltersï¼stat:çæ§ç»è®¡ãlog4jï¼æ¥å¿è®°å½ãwallï¼é²å¾¡sql注å
¥ |
| | | #妿å
è®¸æ¶æ¥é java.lang.ClassNotFoundException: org.apache.log4j.Priority |
| | | #å导å
¥ log4j ä¾èµå³å¯ï¼Maven å°åï¼https://mvnrepository.com/artifact/log4j/log4j |
| | | filters: stat,wall,log4j |
| | | maxPoolPreparedStatementPerConnectionSize: 20 |
| | | useGlobalDataSourceStat: true |
| | | connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 |
| | | |
| | | #ojdbc: |
| | | # jdbcUrl: jdbc:postgresql://192.168.20.106:5432/langfang |
| | | # driverclass: org.postgresql.Driver |
| | | # username: postgres |
| | | # password: postgres |
| | | redis: |
| | | host: 192.168.20.39 |
| | | port: 6379 |
| | | password: |
| | | database: 1 |
| | | |
| | | mybatis: |
| | | type-aliases-package: com.terra.land.mapper |