zoukankan      html  css  js  c++  java
  • ssh2


    创建一个jdbc.properties文件
    url=jdbc:mysql://xx
    user=root
    在spring-config中创建applicationContext.xml文件
    编写
    <cxt:property-placeholder location="classpath:jdbc.properties"/>
    <bean class="com.yededu.testmaven.m1.A" scope="prototype">
    <property name="user" value="${user}" />
    <property name="url" value="${url}" />
    </bean>

    可以在一个文件中写,如xx.xml
    <bean class="com.yededu.testmaven.m1.A" scope="prototype">
    <property name="user" value="${user}" />
    <property name="url" value="${url}" />
    </bean>

    然后在另一个文件中用下列代替
    <import resoure="classpath:xx.xml"/>

    也可以
    <cxt:property-placeholder location=“classpath:jdbc.properties"/>
    <cxt:annotation-config />
    <cxt:component-scan base-package="目录名"/>
    目录下的类:
    要加@Component当然不用加get和set了
    默认值要用@Value("${url}")
    使用另一个类要用@Autowired自动注入也可以用@Resource(这个使用较少)

    @Component基础组件:@Service业务层、@Repository存储层、@Resource(name)

    测试依赖
    <dependencies>
    <dependency>
    <groupId>org.springframenwork</groupId>
    <artifactId>spring-test<artifactId>
    <version>5.1.9RELEASE</version>
    </dependency>
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit<artifactId>
    <version>4.12</version>
    <scope>test</scope>
    </dependency>
    </dependencies>

    测试类要加
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath:applicationContext.xml")

    类用自动注入

    测试方法加@Test标注

  • 相关阅读:
    SVG Stroke属性
    C# 线程同步之排它锁/Monitor监视器类
    在Mac OS X Yosemite 10.10.3 中搭建第一个 ASP.NET 5 Web 项目
    jquery 之 Deferred 使用与实现
    jQuery 之 Callback 实现
    在解决方案中所使用 NuGet 管理软件包依赖
    下载和使用 Open XML PowerTools
    下载和编译 Open XML SDK
    Open XML SDK 在线编程黑客松
    VS2013 解决方案文件结构分析
  • 原文地址:https://www.cnblogs.com/xiao-c-s/p/12420037.html
Copyright © 2011-2022 走看看