package jack.ch3.annotation;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import java.lang.annotation.*;
/**
* Created by jack on 2017/7/15.
* 组合注解
*/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Configuration //组合@Configuration元注解
@ComponentScan //组合@ComponentScan元注解
public @interface WiselyConfiguration {
//覆盖value参数
String [] value() default {};
}
演示服务的Bean:
package jack.ch3.annotation;
import org.springframework.stereotype.Service;
/**
* Created by jack on 2017/7/15.
*/
@Service
public class DemoService {
public void outputResult(){
System.out.println("从组合注解配置照样获取的Bean");
}
}
配置类:
package jack.ch3.annotation;
/**
* Created by jack on 2017/7/15.
*/
//使用@WiselyConfiguration组合注解替代@Configuration和@ComponentScan
@WiselyConfiguration("jack.ch3.annotation")
public class DemoConfig {
}
测试代码如下:
package jack.ch3.annotation;
import jack.ch3.conditional.ConditionConfig;
import jack.ch3.conditional.ListServer;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
/**
* Created by jack on 2017/7/15.
*/
public class MainTest12 {
public static void main(String [] args){
//AnnotationConfigApplicationContext作为spring容器,接受一个配置类作为参数
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(DemoConfig.class);
DemoService demoService = context.getBean(DemoService.class);
demoService.outputResult();
context.close();
}
}
运行程序,输出如下:
D:\java\jdk1.8.0_111\bin\java -Didea.launcher.port=7535 "-Didea.launcher.bin.path=D:\programmingsoftware\IDEA\JetBrains\IntelliJ IDEA 2016.3.2\bin" -Dfile.encoding=UTF-8 -classpath "D:\java\jdk1.8.0_111\jre\lib\charsets.jar;D:\java\jdk1.8.0_111\jre\lib\deploy.jar;D:\java\jdk1.8.0_111\jre\lib\ext\access-bridge-64.jar;D:\java\jdk1.8.0_111\jre\lib\ext\cldrdata.jar;D:\java\jdk1.8.0_111\jre\lib\ext\dnsns.jar;D:\java\jdk1.8.0_111\jre\lib\ext\jaccess.jar;D:\java\jdk1.8.0_111\jre\lib\ext\jfxrt.jar;D:\java\jdk1.8.0_111\jre\lib\ext\localedata.jar;D:\java\jdk1.8.0_111\jre\lib\ext\nashorn.jar;D:\java\jdk1.8.0_111\jre\lib\ext\sunec.jar;D:\java\jdk1.8.0_111\jre\lib\ext\sunjce_provider.jar;D:\java\jdk1.8.0_111\jre\lib\ext\sunmscapi.jar;D:\java\jdk1.8.0_111\jre\lib\ext\sunpkcs11.jar;D:\java\jdk1.8.0_111\jre\lib\ext\zipfs.jar;D:\java\jdk1.8.0_111\jre\lib\javaws.jar;D:\java\jdk1.8.0_111\jre\lib\jce.jar;D:\java\jdk1.8.0_111\jre\lib\jfr.jar;D:\java\jdk1.8.0_111\jre\lib\jfxswt.jar;D:\java\jdk1.8.0_111\jre\lib\jsse.jar;D:\java\jdk1.8.0_111\jre\lib\management-agent.jar;D:\java\jdk1.8.0_111\jre\lib\plugin.jar;D:\java\jdk1.8.0_111\jre\lib\resources.jar;D:\java\jdk1.8.0_111\jre\lib\rt.jar;E:\webworkspace\IdeaProjects\springstudy1\target\classes;C:\Users\wj\.m2\repository\org\springframework\spring-context\4.1.6.RELEASE\spring-context-4.1.6.RELEASE.jar;C:\Users\wj\.m2\repository\org\springframework\spring-beans\4.1.6.RELEASE\spring-beans-4.1.6.RELEASE.jar;C:\Users\wj\.m2\repository\org\springframework\spring-core\4.1.6.RELEASE\spring-core-4.1.6.RELEASE.jar;C:\Users\wj\.m2\repository\commons-logging\commons-logging\1.2\commons-logging-1.2.jar;C:\Users\wj\.m2\repository\org\springframework\spring-expression\4.1.6.RELEASE\spring-expression-4.1.6.RELEASE.jar;C:\Users\wj\.m2\repository\org\springframework\spring-aop\4.1.6.RELEASE\spring-aop-4.1.6.RELEASE.jar;C:\Users\wj\.m2\repository\aopalliance\aopalliance\1.0\aopalliance-1.0.jar;C:\Users\wj\.m2\repository\org\aspectj\aspectjrt\1.8.5\aspectjrt-1.8.5.jar;C:\Users\wj\.m2\repository\org\aspectj\aspectjweaver\1.8.5\aspectjweaver-1.8.5.jar;C:\Users\wj\.m2\repository\commons-io\commons-io\2.3\commons-io-2.3.jar;C:\Users\wj\.m2\repository\javax\annotation\jsr250-api\1.0\jsr250-api-1.0.jar;D:\programmingsoftware\IDEA\JetBrains\IntelliJ IDEA 2016.3.2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain jack.ch3.annotation.MainTest12
七月 15, 2017 3:27:09 下午 org.springframework.context.annotation.AnnotationConfigApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@5d099f62: startup date [Sat Jul 15 15:27:09 CST 2017]; root of context hierarchy
从组合注解配置照样获取的Bean
七月 15, 2017 3:27:09 下午 org.springframework.context.annotation.AnnotationConfigApplicationContext doClose
信息: Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@5d099f62: startup date [Sat Jul 15 15:27:09 CST 2017]; root of context hierarchy
Process finished with exit code 0
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package org.springframework.scheduling.annotation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;
import org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor;
@Configuration
public class SchedulingConfiguration {
public SchedulingConfiguration() {
}
@Bean(
name = {"org.springframework.context.annotation.internalScheduledAnnotationProcessor"}
)
@Role(2)
public ScheduledAnnotationBeanPostProcessor scheduledAnnotationProcessor() {
return new ScheduledAnnotationBeanPostProcessor();
}
}
2,第二类:依据条件选择配置类
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package org.springframework.scheduling.annotation;
import java.lang.annotation.Annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.AsyncConfigurationSelector;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import({AsyncConfigurationSelector.class})
public @interface EnableAsync {
Class extends Annotation> annotation() default Annotation.class;
boolean proxyTargetClass() default false;
AdviceMode mode() default AdviceMode.PROXY;
int order() default 2147483647;
}
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package org.springframework.scheduling.annotation;
import org.springframework.context.annotation.AdviceMode;
import org.springframework.context.annotation.AdviceModeImportSelector;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.ProxyAsyncConfiguration;
public class AsyncConfigurationSelector extends AdviceModeImportSelector {
private static final String ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME = "org.springframework.scheduling.aspectj.AspectJAsyncConfiguration";
public AsyncConfigurationSelector() {
}
public String[] selectImports(AdviceMode adviceMode) {
switch(null.$SwitchMap$org$springframework$context$annotation$AdviceMode[adviceMode.ordinal()]) {
case 1:
return new String[]{ProxyAsyncConfiguration.class.getName()};
case 2:
return new String[]{"org.springframework.scheduling.aspectj.AspectJAsyncConfiguration"};
default:
return null;
}
}
}
3,第三类:动态注册Bean
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package org.springframework.context.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.springframework.context.annotation.AspectJAutoProxyRegistrar;
import org.springframework.context.annotation.Import;
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Import({AspectJAutoProxyRegistrar.class})
public @interface EnableAspectJAutoProxy {
boolean proxyTargetClass() default false;
}
package jack.ch3.test;
/**
* Created by jack on 2017/7/16.
*/
public class TestBean {
private String content;
public TestBean(String content) {
this.content = content;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
配置类:
package jack.ch3.test;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
/**
* Created by jack on 2017/7/16.
*/
@Configuration
public class TestConfig {
@Bean
@Profile("dev")
public TestBean devTestBean(){
return new TestBean("from development profile");
}
@Bean
@Profile("prod")
public TestBean prodTestBean(){
return new TestBean("from production profile");
}
}
测试:
在src/test/java下的代码:
package jack.ch3.test;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Created by jack on 2017/7/16.
*/
@RunWith(SpringJUnit4ClassRunner.class)//SpringJUnit4ClassRunner在JUnit环境下提供Spring TestContext Framework的功能
@ContextConfiguration(classes = {TestConfig.class}) //@ContextConfiguration用来加载配置ApplicationContext,其中classes属性用来加载配置类
@ActiveProfiles("prod") //@ActiveProfiles用来声明活动的profile
public class DemoBeanIntegrationTests {
@Autowired //可使用普通的@Autowired注入Bean
private TestBean testBean;
@Test //测试代码,通过JUnit的Assert来校验是否和预期一致
public void prodBeanShouldInject(){
String expected = "from production profile";
String actual = testBean.getContent();
Assert.assertEquals(expected,actual);
}
}
我们都晓得java实现线程2种方式,一个是继承Thread,另一个是实现Runnable。
模拟窗口买票,第一例子继承thread,代码如下
package thread;
public class ThreadTest {
public static void main(String[] args) {
Thread1 t1 = new Thread1(
#include<iostream>
using namespace std;
//辅助函数,交换两数之值
template<class T>
void mySwap(T &x, T &y){
T temp = x;
x = y;
y = temp;
}
const int size = 10;
//一、用直接插入排
对日期类型的数据进行序列化和反序列化时,需要考虑如下问题:
1. 序列化时,Date对象序列化的字符串日期格式如何
2. 反序列化时,把日期字符串序列化为Date对象,也需要考虑日期格式问题
3. Date A -> str -> Date B,A和B对象是否equals
默认序列化和反序列化
import com
1. DStream的类说明文档:
/**
* A Discretized Stream (DStream), the basic abstraction in Spark Streaming, is a continuous
* sequence of RDDs (of the same type) representing a continuous st
ReplayingDecoder是FrameDecoder的子类,不熟悉FrameDecoder的,可以先看看
http://bylijinnan.iteye.com/blog/1982618
API说,ReplayingDecoder简化了操作,比如:
FrameDecoder在decode时,需要判断数据是否接收完全:
public class IntegerH
1.js中用正则表达式 过滤特殊字符, 校验所有输入域是否含有特殊符号function stripscript(s) { var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~!@#¥……&*()——|{}【】‘;:”“'。,、?]"
经常在写shell脚本时,会碰到要以另外一个用户来执行相关命令,其方法简单记下:
1、执行单个命令:su - user -c "command"
如:下面命令是以test用户在/data目录下创建test123目录
[root@slave19 /data]# su - test -c "mkdir /data/test123"