parent
f6d2781056
commit
bd22c80270
@ -1,40 +0,0 @@ |
|||||||
package org.pqh.core.annotation; |
|
||||||
|
|
||||||
import org.pqh.core.util.LogManger; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
import org.springframework.context.annotation.ImportSelector; |
|
||||||
import org.springframework.core.type.AnnotationMetadata; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by reborn on 2017/9/20. |
|
||||||
* 按条件导入配置类 |
|
||||||
*/ |
|
||||||
public class ConfigurationSelector implements ImportSelector,LogManger{ |
|
||||||
@Override |
|
||||||
public String[] selectImports(AnnotationMetadata annotationMetadata) { |
|
||||||
String appPath=this.getClass().getResource("").getPath(); |
|
||||||
log.info("appPath="+appPath); |
|
||||||
//根据配置类判断
|
|
||||||
if(annotationMetadata.getClassName().equals("org.pqh.config.SpringConfig")){ |
|
||||||
return new String[]{"org.pqh.config.WebCrawlerConfig"}; |
|
||||||
}//根据配置类已有注解判断
|
|
||||||
else if(annotationMetadata.getAnnotationTypes().contains(Configuration.class.getName())){ |
|
||||||
return new String[]{"org.pqh.aaaaaaaaaaaa"}; |
|
||||||
} |
|
||||||
//根据配置类路径判断
|
|
||||||
else if(appPath!=null&&appPath.contains("/web/WEB-INF")){ |
|
||||||
return new String[]{"org.pqh.bbbbbbbbbb"}; |
|
||||||
} |
|
||||||
//根据系统信息
|
|
||||||
else if("XXXX".equals(System.getProperty("XXXX"))){ |
|
||||||
return new String[]{"org.pqh.cccccccccc"}; |
|
||||||
} |
|
||||||
//根据环境变量
|
|
||||||
else if("XXX".equals(System.getenv("XXXX"))){ |
|
||||||
return new String[]{"org.pqh.ddddddddddd"}; |
|
||||||
} |
|
||||||
else{ |
|
||||||
return new String[0]; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,64 +0,0 @@ |
|||||||
package org.pqh.core.util; |
|
||||||
|
|
||||||
import org.springframework.beans.BeansException; |
|
||||||
import org.springframework.beans.factory.config.BeanDefinition; |
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder; |
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry; |
|
||||||
import org.springframework.context.ApplicationContext; |
|
||||||
import org.springframework.context.ApplicationContextAware; |
|
||||||
import org.springframework.context.ConfigurableApplicationContext; |
|
||||||
import org.springframework.context.annotation.Lazy; |
|
||||||
import org.springframework.stereotype.Component; |
|
||||||
|
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
/** |
|
||||||
* Created by reborn on 2017/9/19. |
|
||||||
*/ |
|
||||||
@Component |
|
||||||
@Lazy(false) |
|
||||||
public class SpringUtil implements ApplicationContextAware,LogManger { |
|
||||||
private static ApplicationContext applicationContext; |
|
||||||
|
|
||||||
public static <T>T getBean(Class<T> c){ |
|
||||||
return applicationContext.getBean(c); |
|
||||||
} |
|
||||||
|
|
||||||
public static <T>T getBean(String beanName){ |
|
||||||
return (T) applicationContext.getBean(beanName); |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { |
|
||||||
log.info("init applicationContext"); |
|
||||||
SpringUtil.applicationContext=applicationContext; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* |
|
||||||
* @param clazz 注册class |
|
||||||
* @param serviceName 注册别名 |
|
||||||
* @param propertyMap 注入属性 |
|
||||||
*/ |
|
||||||
public static void addBean(Class clazz,String serviceName,Map<String,Object> propertyMap){ |
|
||||||
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(clazz); |
|
||||||
if(propertyMap!=null){ |
|
||||||
for(String key:propertyMap.keySet()){ |
|
||||||
beanDefinitionBuilder.addPropertyValue(key, propertyMap.get(key)); |
|
||||||
} |
|
||||||
} |
|
||||||
registerBean(serviceName, beanDefinitionBuilder.getRawBeanDefinition()); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* @desc 向spring容器注册bean |
|
||||||
* @param beanName |
|
||||||
* @param beanDefinition |
|
||||||
*/ |
|
||||||
private static void registerBean(String beanName, BeanDefinition beanDefinition) { |
|
||||||
ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; |
|
||||||
BeanDefinitionRegistry beanDefinitonRegistry = (BeanDefinitionRegistry) configurableApplicationContext |
|
||||||
.getBeanFactory(); |
|
||||||
beanDefinitonRegistry.registerBeanDefinition(beanName, beanDefinition); |
|
||||||
} |
|
||||||
} |
|
@ -1,7 +0,0 @@ |
|||||||
package org.pqh.config; |
|
||||||
|
|
||||||
import org.pqh.core.annotation.EnableWebCrawlerConfiguration; |
|
||||||
|
|
||||||
@EnableWebCrawlerConfiguration |
|
||||||
public class WebCrawlerConfig { |
|
||||||
} |
|
@ -0,0 +1,18 @@ |
|||||||
|
package org.pqh.thrift; |
||||||
|
|
||||||
|
import org.apache.thrift.TException; |
||||||
|
|
||||||
|
public class QueryImp implements TestQry.Iface { |
||||||
|
@Override |
||||||
|
public QryResult qryTest(int qryCode) throws TException { |
||||||
|
QryResult result = new QryResult(); |
||||||
|
if(qryCode==1){ |
||||||
|
result.code = 1; |
||||||
|
result.msg = "success"; |
||||||
|
}else{ |
||||||
|
result.code = 0; |
||||||
|
result.msg = "fail"; |
||||||
|
} |
||||||
|
return result; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,39 @@ |
|||||||
|
package org.pqh.thrift; |
||||||
|
|
||||||
|
import org.apache.thrift.protocol.TBinaryProtocol; |
||||||
|
import org.apache.thrift.protocol.TProtocol; |
||||||
|
import org.apache.thrift.transport.TFramedTransport; |
||||||
|
import org.apache.thrift.transport.TSocket; |
||||||
|
import org.apache.thrift.transport.TTransport; |
||||||
|
|
||||||
|
public class ThriftClientDemo { |
||||||
|
private final static int DEFAULT_QRY_CODE = 1; |
||||||
|
public static void main(String[] args){ |
||||||
|
try { |
||||||
|
TTransport tTransport = getTTransport(); |
||||||
|
TProtocol protocol = new TBinaryProtocol(tTransport); |
||||||
|
TestQry.Client client = new TestQry.Client(protocol); |
||||||
|
QryResult result = client.qryTest(DEFAULT_QRY_CODE); |
||||||
|
System.out.println("code="+result.code+" msg="+result.msg); |
||||||
|
}catch (Exception e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
private static TTransport getTTransport() throws Exception{ |
||||||
|
try{ |
||||||
|
TTransport tTransport = getTTransport("127.0.0.1", 2233, 5000); |
||||||
|
if(!tTransport.isOpen()){ |
||||||
|
tTransport.open(); |
||||||
|
} |
||||||
|
return tTransport; |
||||||
|
}catch(Exception e){ |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
return null; |
||||||
|
} |
||||||
|
private static TTransport getTTransport(String host, int port, int timeout) { |
||||||
|
final TSocket tSocket = new TSocket(host, port, timeout); |
||||||
|
final TTransport transport = new TFramedTransport(tSocket); |
||||||
|
return transport; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,27 @@ |
|||||||
|
package org.pqh.thrift; |
||||||
|
|
||||||
|
import org.apache.thrift.TProcessorFactory; |
||||||
|
import org.apache.thrift.protocol.TBinaryProtocol; |
||||||
|
import org.apache.thrift.server.TNonblockingServer; |
||||||
|
import org.apache.thrift.server.TServer; |
||||||
|
import org.apache.thrift.transport.TFramedTransport; |
||||||
|
import org.apache.thrift.transport.TNonblockingServerSocket; |
||||||
|
import org.apache.thrift.transport.TTransportException; |
||||||
|
|
||||||
|
public class ThriftServerDemo { |
||||||
|
public static void main(String[] args) { |
||||||
|
|
||||||
|
try { |
||||||
|
TNonblockingServerSocket socket = new TNonblockingServerSocket(2233); |
||||||
|
TestQry.Processor processor = new TestQry.Processor(new QueryImp()); |
||||||
|
TNonblockingServer.Args arg = new TNonblockingServer.Args(socket); |
||||||
|
arg.protocolFactory(new TBinaryProtocol.Factory()); |
||||||
|
arg.transportFactory(new TFramedTransport.Factory()); |
||||||
|
arg.processorFactory(new TProcessorFactory(processor)); |
||||||
|
TServer server = new TNonblockingServer (arg); |
||||||
|
server.serve(); |
||||||
|
} catch (TTransportException e) { |
||||||
|
e.printStackTrace(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,23 @@ |
|||||||
|
/** |
||||||
|
* 文件名为TestQry.thrift |
||||||
|
* 实现功能:创建一个查询结果struct和一个服务接口service |
||||||
|
* 基于:thrift-0.9.2 |
||||||
|
**/ |
||||||
|
namespace java com.thrift |
||||||
|
struct QryResult { |
||||||
|
/** |
||||||
|
*返回码, 1成功,0失败 |
||||||
|
*/ |
||||||
|
1:i32 code; |
||||||
|
/** |
||||||
|
*响应信息 |
||||||
|
*/ |
||||||
|
2:string msg; |
||||||
|
} |
||||||
|
service TestQry{ |
||||||
|
/** |
||||||
|
* 测试查询接口,当qryCode值为1时返回"成功"的响应信息,qryCode值为其他值时返回"失败"的响应信息 |
||||||
|
* @param qryCode测试参数 |
||||||
|
*/ |
||||||
|
QryResult qryTest(1:i32 qryCode) |
||||||
|
} |
@ -1,11 +1,8 @@ |
|||||||
#-----------------------hibernateÅäÖÃ----------------------------- |
#-----------------------hibernate\u914D\u7F6E----------------------------- |
||||||
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect |
hibernate.dialect=org.hibernate.dialect.MySQL57Dialect |
||||||
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver |
hibernate.connection.driver_class=com.mysql.cj.jdbc.Driver |
||||||
hibernate.connection.url=jdbc:mysql://mikuhime.xyz:3306/webcrawler?serverTimezone=UTC |
hibernate.connection.url=jdbc:mysql://127.0.0.1:3306/webcrawler?serverTimezone=UTC |
||||||
hibernate.connection.username=bilibili |
hibernate.connection.username=bilibili |
||||||
hibernate.connection.password=2233 |
hibernate.connection.password=2233 |
||||||
#-----------------------DruidDataSourceÅäÖÃ----------------------- |
#-----------------------DruidDataSource\u914D\u7F6E----------------------- |
||||||
druid.maxActive=20 |
druid.maxActive=20 |
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in new issue