springboot常用注解和配置整理
所属分类 spring
浏览量 1370
@RestController
@ComponentScan(basePackages = {"com.dyyx", "cn.dyyx"})
@Configuration
@EnableAutoConfiguration
@SpringBootApplication
@ImportResource({"classpath:spring/demo.xml"})
@EnableConfigurationProperties
@EnableTransactionManagement
public class AppMain extends SpringBootServletInitializer implements ApplicationContextAware
org.springframework.boot.web.servlet.support.SpringBootServletInitializer
@RequestMapping("/ok.htm")
String ok(@RequestParam(defaultValue = "false") String down) {
return "ok";
}
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,XADataSourceAutoConfiguration.class})
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,XADataSourceAutoConfiguration.class})
禁用指定的自动配置
springboot禁用特定的自动配置类
@RestController
public class XXXController
@Resource(name = "xxxService")
private XxxService xxxService;
@RequestMapping(value = "xxxService", method = { RequestMethod.POST, RequestMethod.GET })
public Object xxxService(HttpServletRequest request) {
@Transactional
public X xxx(Map params)
spring常用注解
spring web 注解
常用配置
spring.application.name=xxx
spring.mvc.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.time-zone=GMT+8
logging.config=classpath:logback-spring.xml
#
server.servlet.path=/api/
server.error.path=/api/error
spring.mvc.throw-exception-if-no-handler-found=true
spring.resources.add-mappings=false
server.error.whitelabel.enabled=false
app.output=${catalina.home}
logging.file=${app.output}/logs/app.log
server.port=8088
server.tomcat.max-threads=200
server.tomcat.accesslog.directory=${app.output}/logs
server.tomcat.accesslog.enabled=true
# datasource 1 =================================================
spring.datasource.druid.ds1.url=
spring.datasource.druid.ds1.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.druid.ds1.username=
spring.datasource.druid.ds1.password=
spring.datasource.druid.ds1.initial-size=3
spring.datasource.druid.ds1.max-active=50
spring.datasource.druid.ds1.min-idle=1
spring.datasource.druid.ds1.max-wait=60000
spring.datasource.druid.ds1.pool-prepared-statements=true
spring.datasource.druid.ds1.max-pool-prepared-statement-per-connection-size=20
spring.datasource.druid.ds1.validation-query=select 1
spring.datasource.druid.ds1.test-on-borrow=false
spring.datasource.druid.ds1.test-on-return=false
spring.datasource.druid.ds1.test-while-idle=true
spring.datasource.druid.ds1.time-between-eviction-runs-millis=60000
spring.datasource.druid.ds1.min-evictable-idle-time-millis=300000
#spring.datasource.druid.max-evictable-idle-time-millis=
spring.datasource.druid.ds2.filters=stat,slf4j
# datasource 2
spring.datasource.druid.ds2.driver-class-name=com.mysql.jdbc.Driver
# spring.jackson.defaultPropertyInclusion=NON_NULL
# mybatis ===========================
mybatis.mapperLocation.ds1=classpath*:mybatis/mapper/mysql/**/*.xml
mybatis.configLocation.ds1=classpath:mybatis/ds1-sqlmap-config.xml
mybatis.mapperLocation.ds2=classpath*:ds2/mybatis/mapper/mysql/*.xml
mybatis.configLocation.ds2=classpath:mybatis/ds2-sqlmap-config.xml
数据源配置类
@Configuration
@MapperScan(basePackages = "cn.dyyx.dao", sqlSessionTemplateRef = "ds1SqlSessionTemplate")
public class DataSource1Cfg {
private static Logger log = LoggerFactory.getLogger(DataSource1Cfg.class);
@Value("${mybatis.configLocation.ds1}")
private String configLocation;
@Value("${mybatis.mapperLocation.ds1}")
private String mapperLocation;
@Primary
@Bean
@ConfigurationProperties("spring.datasource.druid.ds1")
public DataSource ds1DataSource() {
return DruidDataSourceBuilder.create().build();
}
@Primary
@Bean(name = "ds1SqlSessionFactory")
public SqlSessionFactory sqlSessionFactory(@Qualifier("ds1DataSource") DataSource datasource) {
SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
sessionFactory.setDataSource(datasource);
sessionFactory.setConfigLocation(new DefaultResourceLoader().getResource(configLocation));
sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(mapperLocation));
return sessionFactory.getObject();
}
@Primary
@Bean(name = "ds1TxManager")
public DataSourceTransactionManager setTransactionManager(
@Qualifier("ds1DataSource") DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
@Primary
@Bean(name = "ds1SqlSessionTemplate")
public SqlSessionTemplate setSqlSessionTemplate(
@Qualifier("ds1SqlSessionFactory") SqlSessionFactory sqlSessionFactory) {
return new SqlSessionTemplate(sqlSessionFactory);
}
}
上一篇
下一篇
网站SEO robots文件写法
kafka知识点整理之概述
2019年杭州的独角兽和准独角兽们
大数据日知录第一章数据分片与路由读书笔记
开发自己的maven插件
aerospike的一些限制