SpringBoot实战笔记:04_Spring Aware

Spring Aware

  • Spring的依赖注入,使得所有的Bean感觉不到Spring容器的存在,也就是说是可以随意更换了IOC容器的,因为Bean之间的耦合度很低。

  • 但有时我们需要在bean中使用spring容器给我们提供的资源(Request等等),这时我们的Bean就必须要意识到Spring容器的存在,才能调用Spring所提供的资源,这就是 Spring Aware

  • 若使用了Spring Aware 则Bean将会与Spring框架耦合。

BeanNameAware
BeanFactoryAware
ApplicationContextAware*
MessageSourceAware
ApplicationEventPublisherAware
ResourceLoaderAware

示例

1,在com.zyf包下创建aware示例.txt

2,在com.zyf包下创建AwareService类(bean类)
package com.zyf;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * Created by zyf on 2018/3/5.
 * 实现两个接口,获得Bean名次和资源加载的服务
 */
@Service
public class AwareService implements BeanNameAware,ResourceLoaderAware {

    /**
     * bean的名字
     */
    private String beanName;
    /**
     * 资源加载器
     */
    private ResourceLoader loader;


    @Override
    public void setBeanName(String s) {
        this.beanName = s;
    }

    @Override
    public void setResourceLoader(ResourceLoader resourceLoader) {
        this.loader = resourceLoader;
    }

    public void outputResource(){
        System.out.println("Bean的名字:"+beanName);
        Resource resource = loader.getResource("classpath:com/zyf/aware示例.txt");
        try {
            System.out.println("ResourceLoader加载的文件内容为:"+ IOUtils.toString(resource.getInputStream()));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
3,在com.zyf包下创建AwareConfig类(配置类)
package com.zyf;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * Created by zyf on 2018/3/5.
 */
@Configuration
@ComponentScan(value = "com.zyf")
public class AwareConfig {
}
3,在com.zyf包下创建Main类(测试)
package com.zyf;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * Created by zyf on 2018/3/5.
 */
public class Main {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext context =
                //未指定要加载哪个配置类
                new AnnotationConfigApplicationContext();
        //后置指定
        context.register(AwareConfig.class);
        //刷新容器,一定要刷新!
        context.refresh();
        AwareService awareService = context.getBean(AwareService.class);
        awareService.outputResource();
    }
}
4,测试结果

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vector<PointVectorPair> points; for (size_t i = 0; i < input->size(); i++) { float px = input->points[i].x; float py = input->points[i].y; float pz = input->points[i].z; float nx = input->points[i].normal_x; float ny = input->points[i].normal_y; float nz = input->points[i].normal_z; points.push_back(PointVectorPair(Kernel::Point_3(px, py, pz), Kernel::Vector_3(nx, ny, nz))); } // ---------------------------------参数设置--------------------------------- const double s_angle = 25; // 平滑度,值越大越平滑,取值范围[0,90] const double edge_s = 0; // 边缘的敏感性取值范围[0,1] const double n_radius = 0.25; // 邻域点搜索半径 const std::size_t n_out = points.size() * 10; // 上采样后的点数 // ----------------------------------上采样---------------------------------- CGAL::edge_aware_upsample_point_set<CGAL::Parallel_if_available_tag>(points, std::back_inserter(points), CGAL::parameters::point_map(CGAL::First_of_pair_property_map<PointVectorPair>()). normal_map(CGAL::Second_of_pair_property_map<PointVectorPair>()). sharpness_angle(s_angle). // 控制输出结果的平滑度,值越大越平滑,取值范围[0,90]。 edge_sensitivity(edge_s). // 边缘的敏感性取值范围[0,1],边缘敏感度越大,在尖锐边缘处插入点的有限度越高 neighbor_radius(n_radius). // 邻域点的个数,如果提供,查询点的邻域是用一个固定的球面计算的半径 // 而不是固定数量的邻居。在这种情况下,参数k用于限制每个球邻域返回点的数量(避免高密度区域的点过多) number_of_output_points(n_out)); // 上采样后的点数 std::cout << "上采样完毕!!!" << std::endl;将上述代码中的CGAL带有法线的点云数据转换PCL库点云数据PointNormal
07-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值