2016年8月

Upgrade pax-url-aether version to 2.4.7 for karaf 4.0.3

Upgrade pax-url-aether version to 2.4.7 for karaf 4.0.3

talend-esb/pom.xml

  • add version variable
    <pax-url-aether.version>2.4.7</pax-url-aether.version>
  • add dependency
<!-- workaround for pax-url-aether bundle (TESB-17522) -->
<dependency>
    <groupId>org.ops4j.pax.url</groupId>
    <artifactId>pax-url-aether</artifactId>
    <version>${pax-url-aether.version}</version>
    <type>jar</type>
</dependency>
  • add copy jar in generate-resources phase
<artifactItem>
    <groupId>org.ops4j.pax.url</groupId>
    <artifactId>pax-url-aether</artifactId>
    <version>${pax-url-aether.version}</version>
    <type>jar</type>
    <outputDirectory>target/dependencies</outputDirectory>
    <destFileName>pax-url-aether-${pax-url-aether.version}.jar</destFileName>
</artifactItem>
  • add replace version in generate-resources phase for framework-${karaf.version}-features.xml file
<!-- patch for Karaf org.apache.karaf.features.core bundle -->
<replace file="target/dependencies/framework-${karaf.version}-features.xml">
    <replacefilter
        token="org.apache.karaf.features/org.apache.karaf.features.core/${karaf.version}&lt;"
        value="org.apache.karaf.features/org.apache.karaf.features.core/${karaf.version}/jar/TESB&lt;"/>
    <!-- patch for upgrading pax-url-aether to 2.4.7 (TESB-17522) -->
    <replacefilter
        token="mvn:org.ops4j.pax.url/pax-url-aether/2.4.3"
        value="mvn:org.ops4j.pax.url/pax-url-aether/${pax-url-aether.version}"/>
</replace>
  • add repo dependencies in pom
<repository>
    <id>ops4j.sonatype.releases</id>
    <name>OPS4J releases repository</name>
    <url>https://oss.sonatype.org/content/repositories/ops4j-releases/</url>
    <releases>
        <enabled>true</enabled>
    </releases>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
</repository>

talend-esb/src/main/descriptors/unix-bin.xml and talend-esb/src/main/descriptors/win-bin.xml

  • exclude startup.properties file <exclude>etc/startup.properties</exclude>
  • copy jar into local repo
<!-- pax-url-aether library patch (TESB-17522) -->
<file>
    <source>${basedir}/target/dependencies/pax-url-aether-${pax-url-aether.version}.jar</source>
    <outputDirectory>/container/system/org/ops4j/pax/url/pax-url-aether/${pax-url-aether.version}/</outputDirectory>
    <fileMode>0644</fileMode>
</file>    

talend-esb/src/main/filtered-resources/etc/org.ops4j.pax.url.mvn.cfg

  • add always param in the cfg file for maven
    org.ops4j.pax.url.mvn.globalUpdatePolicy=always

talend-esb/src/main/filtered-resources/etc/startup.properties

  • add mvn\:org.ops4j.pax.url/pax-url-aether/2.4.7 = 5 in this file

https://github.com/Talend/tesb-rt-se/commit/a72e35789b1d3a33d8b97b641d25f4df8b0ab8ea

Spring Bean's Scope

Bean scopes

  • @Service
  • @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
ScopeDescription

singleton

Scopes a single bean definition to a single object instance per Spring IoC container.

prototype

Scopes a single bean definition to any number of object instances.

request

Scopes a single bean definition to the lifecycle of a single HTTP request; that is each and every HTTP request will have its own instance of a bean created off the back of a single bean definition. Only valid in the context of a web-aware Spring ApplicationContext.

session

Scopes a single bean definition to the lifecycle of a HTTP Session. Only valid in the context of a web-aware Spring ApplicationContext.

global session

Scopes a single bean definition to the lifecycle of a global HTTP Session. Typically only valid when used in a portlet context. Only valid in the context of a web-aware Spring ApplicationContext.

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

@Service
@Scope("prototype")
public class DemoPrototypeService {
    public DemoPrototypeService() {
    }
}
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Service;

/**
 * Created by yyi on 8/8/2016. Bean
 */
@Service
public class DemoService {
//    @Value("another class attribute")
    @Value("classpath:/ch2/el/test.txt")
    private Resource another;

    public Resource getAnother(){
        return another;
    }
    public void setAnother(Resource another) {
        this.another = another;
    }
}
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;

/**
 * Created by yyi on 8/8/2016.
 */
@Configuration
@ComponentScan("ch2.el")
@PropertySource("classpath:ch2/el/test.properties")
public class ElConfig {
    @Value("I Love You!") //1
    private String normal;

    @Value("#{systemProperties['os.name']}") //2
    private String osName;

    @Value("#{ T(java.lang.Math).random() * 100.0 }") //3
    private double randomNumber;

    @Value("#{demoService.another}") //4
    private Resource fromAnother;

    @Value("classpath:/ch2/el/test.txt") //5
    private Resource testFile;

    @Value("http://www.baidu.com") //6
    private Resource testUrl;

    @Value("${company.team}") //7
    private String bookName;

    @Autowired
    private Environment environment; //7

    @Bean //7
    public static PropertySourcesPlaceholderConfigurer propertyConfigure() {
        return new PropertySourcesPlaceholderConfigurer();
    }
    public void outputResource() {
        try {
            System.out.println(normal);
            System.out.println(osName);
            System.out.println(randomNumber);
            System.out.println(fromAnother);
            System.out.println(IOUtils.toString(fromAnother.getInputStream()));

            System.out.println(IOUtils.toString(testFile.getInputStream()));
            System.out.println(IOUtils.toString(testUrl.getInputStream()));
            System.out.println(bookName);
            System.out.println(environment.getProperty("book.author"));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}

Spring AOP

Maven 依赖

    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.8.5</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjweaver</artifactId>
        <version>1.8.5</version>
    </dependency>

  • AspectJ @Before
  • AspectJ @After
  • AspectJ @AfterReturning
  • AspectJ @Around