-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,110 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
# Compiled class file | ||
*.class | ||
|
||
# Log file | ||
*.log | ||
|
||
# BlueJ files | ||
*.ctxt | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.nar | ||
*.ear | ||
*.zip | ||
*.tar.gz | ||
*.rar | ||
|
||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml | ||
hs_err_pid* | ||
|
||
target | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
proxypoolweb/src/main/java/com/linzeming/proxypoolweb/config/MainConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
package com.linzeming.proxypoolweb.config; | ||
|
||
import com.alibaba.druid.pool.DruidDataSource; | ||
import com.baomidou.mybatisplus.annotation.DbType; | ||
import com.baomidou.mybatisplus.core.MybatisConfiguration; | ||
import com.baomidou.mybatisplus.core.config.GlobalConfig; | ||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; | ||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; | ||
import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; | ||
import com.linzeming.proxypoolweb.util.Constants; | ||
import org.apache.ibatis.plugin.Interceptor; | ||
import org.mybatis.spring.mapper.MapperScannerConfigurer; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
import org.springframework.web.servlet.view.InternalResourceViewResolver; | ||
import redis.clients.jedis.JedisPool; | ||
import redis.clients.jedis.JedisPoolConfig; | ||
|
||
@Configuration | ||
@ComponentScan(basePackages = "com.linzeming.proxypoolweb.*") | ||
public class MainConfig { | ||
|
||
/** | ||
* redis配置 | ||
* @return | ||
*/ | ||
@Bean | ||
public JedisPool jedisPool() { | ||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); | ||
//控制一个pool可分配多少个jedis实例 | ||
jedisPoolConfig.setMaxTotal(20); | ||
//控制一个pool最多有多少个状态为idle(空闲)的jedis实例 | ||
jedisPoolConfig.setMaxIdle(10); | ||
//表示当borrow一个jedis实例时,最大的等待时间,如果超过等待时间,则直接抛出JedisConnectionException | ||
jedisPoolConfig.setMaxWaitMillis(5000); | ||
//在borrow一个jedis实例时,是否提前进行validate操作;如果为true,则得到的jedis实例均是可用的 | ||
jedisPoolConfig.setTestOnBorrow(true); | ||
JedisPool jedisPool = new JedisPool(jedisPoolConfig, "10.0.0.88", 6379); | ||
return jedisPool; | ||
} | ||
|
||
/** | ||
* 数据库连接池配置, mybatis配置 | ||
* @return | ||
*/ | ||
@Bean | ||
public DruidDataSource dataSource() { | ||
DruidDataSource dataSource = new DruidDataSource(); | ||
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver"); | ||
dataSource.setUsername("javadev"); | ||
dataSource.setPassword("javadev"); | ||
dataSource.setUrl("jdbc:mysql://10.0.0.88:3306/proxypool?rewriteBatchedStatements=true"); | ||
dataSource.setMaxActive(Constants.dataSourceMaxActive); | ||
dataSource.setMaxWait(Constants.dataSourceMaxWait); | ||
return dataSource; | ||
} | ||
|
||
@Bean | ||
public DataSourceTransactionManager dataSourceTransactionManager(){ | ||
DataSourceTransactionManager dataSourceTransactionManager = new DataSourceTransactionManager(); | ||
dataSourceTransactionManager.setDataSource(dataSource()); // todo | ||
return dataSourceTransactionManager; | ||
} | ||
|
||
/* | ||
mybatis plus配置 | ||
*/ | ||
@Bean | ||
public MybatisPlusInterceptor mybatisPlusInterceptor(){ | ||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); | ||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); | ||
return interceptor; | ||
} | ||
|
||
@Bean | ||
public MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean(){ | ||
MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean = new MybatisSqlSessionFactoryBean(); | ||
mybatisSqlSessionFactoryBean.setDataSource(dataSource()); // todo | ||
mybatisSqlSessionFactoryBean.setConfiguration(mybatisConfiguration()); | ||
Interceptor[] plugins = {mybatisPlusInterceptor()}; | ||
mybatisSqlSessionFactoryBean.setPlugins(plugins); | ||
// mybatisSqlSessionFactoryBean.setTypeAliasesPackage(); | ||
return mybatisSqlSessionFactoryBean; | ||
} | ||
|
||
@Bean | ||
public MybatisConfiguration mybatisConfiguration(){ | ||
MybatisConfiguration mybatisConfiguration = new MybatisConfiguration(); | ||
mybatisConfiguration.setMapUnderscoreToCamelCase(true); | ||
return mybatisConfiguration; | ||
} | ||
@Bean | ||
public GlobalConfig globalConfig(){ | ||
GlobalConfig globalConfig = new GlobalConfig(); | ||
return globalConfig; | ||
} | ||
@Bean | ||
public GlobalConfig.DbConfig dbConfig(){ | ||
GlobalConfig.DbConfig dbConfig = new GlobalConfig.DbConfig(); | ||
return dbConfig; | ||
} | ||
|
||
@Bean | ||
public MapperScannerConfigurer mapperScannerConfigurer(){ | ||
MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer(); | ||
mapperScannerConfigurer.setSqlSessionFactoryBeanName("mybatisSqlSessionFactoryBean"); | ||
mapperScannerConfigurer.setBasePackage("com.linzeming.proxypoolweb.mapper"); | ||
return mapperScannerConfigurer; | ||
} | ||
|
||
|
||
// @Bean | ||
// @ConditionalOnMissingBean | ||
// public InternalResourceViewResolver defaultViewResolver() { | ||
// InternalResourceViewResolver resolver = new InternalResourceViewResolver(); | ||
// resolver.setPrefix("/templates"); | ||
// resolver.setSuffix(".html"); | ||
//// resolver.setPrefix(this.mvcProperties.getView().getPrefix()); | ||
//// resolver.setSuffix(this.mvcProperties.getView().getSuffix()); | ||
// return resolver; | ||
// } | ||
} |
16 changes: 16 additions & 0 deletions
16
proxypoolweb/src/main/java/com/linzeming/proxypoolweb/controller/HelloController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.linzeming.proxypoolweb.controller; | ||
|
||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@Controller | ||
public class HelloController { | ||
@GetMapping({"/hello"}) | ||
public String hello(Model model, @RequestParam(value="name", required=false, defaultValue="World") String name) { | ||
model.addAttribute("name", name); | ||
System.out.println("rebushuceshi"); | ||
return "hello"; | ||
} | ||
} |
Oops, something went wrong.