- 浏览: 45176 次
最新评论
spring的基于java的项目配置示例。
import org.springframework.web.context.AbstractContextLoaderInitializer; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; public class CmsAppInitializer extends AbstractContextLoaderInitializer { @Override protected WebApplicationContext createRootApplicationContext() { AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext(); applicationContext.register(RootConfig.class); return applicationContext; } }
import java.util.Properties; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.PropertiesFactoryBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.ImportResource; import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySources; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.env.Environment; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import com.xxx.springutil.failfast.FailFastFromPropertyAndSystemProperty; @Configuration @ComponentScan(basePackages={"com.xxx.cms"}) @PropertySources({ @PropertySource(value="classpath:/hs-cms-srv-properties/hs-cms-srv-env.properties"), @PropertySource(value="file:${appHome}/hs-cms-srv-env.properties", ignoreResourceNotFound=true) }) @ImportResource(value = { "classpath:/hs-cms-srv-config/spring-memcached.xml", // "classpath:/hs-cms-srv-config/spring-elasticsearch.xml", "classpath:/hs-cms-srv-config/spring-dubbo.xml", "classpath:/hs-core-srv-client-config/context-client.xml", "classpath:/hs-cms-srv-config/spring-redis-client.xml", "classpath*:/hs-mq-client-config/spring-jms-common.xml", "classpath*:/hs-mq-client-config/spring-jms-producer.xml" }) @Import({ MybatisConfig.class, ElasticSearchConfig.class }) public class RootConfig { @Autowired Environment env; @Bean public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() { final PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer(); pspc.setIgnoreResourceNotFound(true); pspc.setIgnoreUnresolvablePlaceholders(true); return pspc; } @Bean public PropertiesFactoryBean appProps() { PropertiesFactoryBean pfb = new PropertiesFactoryBean(); pfb.setSingleton(true); Properties properties = new Properties(); properties.put("appEnv", env.getProperty("hs.admin.env", "dev")); pfb.setProperties(properties); return pfb; } @Bean public FailFastFromPropertyAndSystemProperty failFastFromPropertyAndSystemProperty() { FailFastFromPropertyAndSystemProperty ff = new FailFastFromPropertyAndSystemProperty(); ff.setIfExistSystemPropertyVar("appHome"); ff.setPropertyValueBySpring(env.getProperty("hs.cms.srv.env", "dev")); ff.setStopWhenPropertyEqualsThisValue("dev"); return ff; } @Bean public ThreadPoolTaskExecutor taskExcutor() { ThreadPoolTaskExecutor taskExcutor = new ThreadPoolTaskExecutor(); taskExcutor.setCorePoolSize(16); taskExcutor.setMaxPoolSize(32); taskExcutor.setQueueCapacity(64); return taskExcutor; } }
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionFactoryBean; import org.mybatis.spring.SqlSessionTemplate; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.DependsOn; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.transaction.support.TransactionTemplate; import com.xxx.dao.GenericMybatisDao; import com.xxx.passwordencrypt.DbPasswordFactoryBean; import com.alibaba.druid.pool.DruidDataSource; @Configuration public class MybatisConfig { private final static String ENV_PRODUCT = "product"; private final static String ENV_BETA = "beta"; @Value("${hs.cms.srv.env}") private String env; @Value("${hs.cms.srv.jdbc.druid.driverClassName}") private String driverClassName; @Value("${hs.cms.srv.jdbc.druid.url}") private String jdbcUrl; @Value("${hs.cms.srv.jdbc.druid.username}") private String username; @Value("${hs.cms.srv.jdbc.druid.password}") private String password; @Value("${hs.cms.srv.jdbc.druid.initialSize}") private Integer initialSize; @Value("${hs.cms.srv.jdbc.druid.maxActive}") private Integer maxActive; // @Value("${hs.cms.srv.jdbc.druid.maxIdle}") // private Integer maxIdle; @Value("${hs.cms.srv.jdbc.druid.minIdle}") private Integer minIdle; @Value("${hs.cms.srv.jdbc.druid.maxWait}") private Integer maxWait; // @Value("${hs.cms.srv.jdbc.druid.removeAbandoned}") // private Boolean removeAbandoned; // @Value("${hs.cms.srv.jdbc.druid.removeAbandonedTimeout}") // private Integer removeAbandonedTimeout; private boolean needDecryptPassword() { return ENV_PRODUCT.equals(env) || ENV_BETA.equals(env); } @Bean(initMethod = "init", destroyMethod = "close") @DependsOn() public DruidDataSource dataSource() throws Exception { if (needDecryptPassword()) { DbPasswordFactoryBean dbPasswordFactoryBean = new DbPasswordFactoryBean(); dbPasswordFactoryBean.setCryptWord(password); password = dbPasswordFactoryBean.getObject(); } DruidDataSource dataSource = new DruidDataSource(); dataSource.setDriverClassName(driverClassName); dataSource.setUrl(jdbcUrl); dataSource.setUsername(username); dataSource.setPassword(password); dataSource.setInitialSize(initialSize); dataSource.setMaxActive(maxActive); // dataSource.setMaxIdle(maxIdle); dataSource.setMinIdle(minIdle); dataSource.setMaxWait(maxWait); dataSource.setTestOnBorrow(true); dataSource.setTestOnReturn(false); dataSource.setTestWhileIdle(true); dataSource.setFilters("mergeStat"); dataSource.setValidationQuery("SELECT 1"); dataSource.setPoolPreparedStatements(true);// MySQL的4.1.0后可开启服务端PreparedStatement的缓存优化 dataSource.setMaxPoolPreparedStatementPerConnectionSize(20);// 设置单个数据库连接缓存的PreparedStatement的条数 // dataSource.setRemoveAbandoned(removeAbandoned); // dataSource.setRemoveAbandonedTimeout(removeAbandonedTimeout); // <property name="filters" value="stat" /> // <property name="minEvictableIdleTimeMillis" value="300000" /> // <property name="timeBetweenEvictionRunsMillis" value="60000" /> // <property name="validationQuery" value="SELECT 1" /> // <property name="testWhileIdle" value="true" /> // <property name="testOnBorrow" value="false" /> // <property name="testOnReturn" value="false" /> return dataSource; } @Bean public DataSourceTransactionManager transactionManager() throws Exception { return new DataSourceTransactionManager(dataSource()); } @Bean public TransactionTemplate transactionTemplate() throws Exception { TransactionTemplate txTemplate = new TransactionTemplate(); txTemplate.setTransactionManager(transactionManager()); return txTemplate; } @Bean public SqlSessionFactory sqlSessionFactory() throws Exception { SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean(); sessionFactory.setDataSource(dataSource()); // sessionFactory.setTypeAliasesPackage("com.huasheng.cms.channel.common.domain"); // sessionFactory.setTypeHandlersPackage("com.huasheng.cms.dao.mybatis.typehandler"); Resource configLocation = new ClassPathResource("/hs-cms-srv-mybatis/mybatis-configuration.xml"); sessionFactory.setConfigLocation(configLocation); ResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver(); Resource [] mappingLocations = patternResolver.getResources("classpath*:/hs-cms-srv-mybatis/**/*Mapper.xml"); sessionFactory.setMapperLocations(mappingLocations); return sessionFactory.getObject(); } @Bean public SqlSessionTemplate sqlSessionTemplate() throws Exception { return new SqlSessionTemplate(sqlSessionFactory()); } @Bean public SqlSessionTemplate sqlSessionTemplateBatch() throws Exception { return new SqlSessionTemplate(sqlSessionFactory(), ExecutorType.BATCH); } @Bean public GenericMybatisDao dao() throws Exception { GenericMybatisDao dao = new GenericMybatisDao(); dao.setMybatisTemplate(sqlSessionTemplate()); return dao; } @Bean public GenericMybatisDao batchDao() throws Exception { GenericMybatisDao dao = new GenericMybatisDao(); dao.setMybatisTemplate(sqlSessionTemplateBatch()); return dao; } }
发表评论
-
简单的压测模拟
2018-05-11 19:52 632import java.time.Duration; i ... -
Java的驼峰与下划线的属性对象互相转换
2018-05-11 19:50 8304import com.xxxx.util.consta ... -
Elastic Search搜索实例
2019-06-16 18:30 522要从现在的公司离职了。记录一下自己针对我们的自己需求所做的搜索 ... -
针对基于Redis Cluster的接口数据缓存删除实现
2018-03-26 10:35 1178首先定义个工具interface,基于Java 8的实现. 主 ... -
简单ELK配合logback搭建日志监控中心
2018-03-20 17:30 1290今天得闲就自己搭了个ELK示例,过程挺简单的。 Elas ... -
spring的基于java的项目配置示例2
2018-03-20 17:32 781import com.xxx.support.config ... -
HttpClient实例
2018-03-16 08:15 616import java.io.IOException; ... -
基于spring data的Elastic Search的配置示例
2018-03-15 17:41 868基于spring data的Elastic Search的配置 ... -
方便jedis cluster操作的工具类
2018-03-15 17:37 2899由于redis的集群 redis cluster不支持keys ... -
爬虫基础类
2018-03-15 17:28 759自己封装的爬虫基础类。 public interfac ... -
基于AOP的ajax的referrer判断
2018-03-15 17:23 1519网页中ajax请求的referrer的值是当前域名。(其实这个 ... -
Java Timestamp从MySQL数据库取出的字符串转换为LocalDateTime
2016-01-26 16:08 9855最新在工作中使用了Java 8的LocalDate ... -
reviewC指针
2014-03-02 22:05 372由于要考试,有C的考核内容。所以今天把C拉出来又看了下,其实基 ... -
Python2.X内置函数学习
2013-12-19 21:52 11241.apply()函数 学过Python的都知道P ... -
学习Python中遇到的问题
2013-09-04 23:26 677最近学习Python中。 先上代码: # -*- codi ...
相关推荐
本项目示例基于spring boot 最新版本(2.1.9)实现,Spring Boot、Spring Cloud 学习示例,将持续更新…… 在基于Spring Boot、Spring Cloud 分布微服务开发过程中,根据实际项目环境,需要选择、集成符合项目...
spring-javaconfig-sample, Spring MVC/Spring Data JPA/Hibernate的spring JavaConfig示例 spring-配置示例自 spring 3.0以来,JavaConfig特性被包含在核心 spring 模块中。 因此Java开发人员可以将 spring bean...
本项目采用Java作为主要开发语言,整合了CSS、JavaScript等前端技术,构建了一个基于SSM(Spring、SpringMVC、MyBatis)框架的CRUD(增删改查)操作示例。该示例共包含46个文件,其中: - Java源文件:14个,涵盖了...
本项目基于Spring boot这一平台,整合流行的开源消息队列中间件ActiveMQ,实现一个向ActiveMQ添加和读取消息的功能。分别实现生产者-消费者模式和发布-订阅模式,作为java编程发送消息和消费消息的基础示例。 源码...
基于SpringBoot+SpringCloud集成了50+个demo的项目示例.zip spring boot demo 是一个Spring Boot、Spring Cloud的项目示例,根据市场主流的后端技术,共集成了50+个demo,未来将持续更新。该项目包含helloworld(快速...
项目概述:本项目命名为 SpringMvc-05 示例,主要采用 Java 语言开发,整合了 SSM(Spring、SpringMVC、MyBatis)框架。项目包含前端和后端两部分,前端使用了 JavaScript、CSS 和 HTML,后端则完全是 Java 实现。...
基于Java Web的电影购票系统源码+项目说明+示例图片.zip ## 项目实现的主要业务功能 ## 1. 用户模块:实时订票、查看订单、账户充值、修改个人信息、猜你喜欢等 2. 管理员模块:票项管理、用户管理、订单管理。 ## ...
SpringBasics-Java 具有基于Java的配置的示例Spring核心概念
二、Spring基于XML装配实验 说明:使用Spring IOC模拟实现账户添加功能程序 1.创建JavaBean类:Account.java 2.创建DAO类: AccountDao.java,模拟账户添加操作 3.创建Service类:AccountService.java,模拟账户添加...
- 使用最新技术栈,社区资源丰富,基于Java 21(Core Module Support 17-21)、Spring Boot 3.2。 (Support Virtual Threads/fibre/loom) - 基于注解的动态查询(Specification),可根据需要扩充查询注解。 - 支持...
柑橘样品 样例应用 Citrus示例应用程序试图证明Citrus如何在不同的集成测试方案中工作。 这些项目可通过Maven执行,并应为您提供有关Citrus测试如何工作的详细信息。 该存储库使用Java DSL和...使用基于注释的端点配置
基于 Java Web 项目的 SpringBoot 框架初始化模板,该模板整合了常用的框架,保证大家在此基础上能够快速开发自己的项目,该模板针对于后端启动开发小而精,本项目会由作者持续更新。 业务特性: 1、使用 Undertow ...
基于JAVA的UDP服务器模型源代码,内含UDP服务器端模型和UDP客户端模型两个小程序,向JAVA初学者演示UDP C/S结构的原理。 简单聊天软件CS模式 2个目标文件 一个简单的CS模式的聊天软件,用socket实现,比较简单。 ...
SpringBootPrimefacesGradle 基于 Java8、Groovy、Gradle、SpringBoot、Jetty、Spring web security、Jsf、Primefaces、Hibernate 和 H2 Db 的示例项目开始调用 gradle 任务 bootRun,停止调用 gradle 任务 bootStop...
弹簧示例Spring 示例:这些示例背后的想法是提供有关如何设置不同替代方案以使用 Spring 框架及其不同模块的快速入门指南。 将有(正在进行的)几个级别,并将对其进行枚举。 项目必须是基于 Groovy 的,但有时可以...
Spring Security多身份验证展示柜基于Spring Boot的示例应用程序,展示了用于多个身份验证流程的案例Java配置-Siteminder SSO和基于表单的登录。入门/运行应用程序克隆存储库,使用maven将其打包为jar,然后从目标...
这是一个基于SpringCloud的微服务架构项目 部署须知 导入db目录下数据库文件到自己的MySQL服务器 修改配置环境(xxx-service/src/main/resources/application.yml,active值决定启用环境配置文件) 修改连接数据库...
基于Spring Boot的Java学习平台是一个**旨在帮助开发者学习和实践Java语言以及Spring Boot框架的项目**。以下是对该平台的介绍: 1. **设计理念**: - 该平台以知识点实例项目的学习模式由浅入深,使学习者能够循序...
1、基于java开发的开源网址导航网站项目源码+数据库+项目说明.zip 2、该资源包括项目的全部源码,下载可以直接使用! 3、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考...
本项目用于Spring-Cloud训练的训练。 项目的配置位于存储库中。 目录 概述 该项目包含基于 spring-boot 的服务: 核心服务: 贷款服务- 负责贷款的商业服务 证券服务- 负责债务管理的后端业务服务 入口点 借贷 UI - ...