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标注

  • 相关阅读:
    .net的25个小技巧
    使用ASP.Net2.0国际化你的网站祥解
    国外C#开源项目(转)
    千千阙歌
    js中var的有或无重复声明和以后的声明
    XMLHttpRequest
    java参数与引用
    Total Commander
    XMLDOM 的async属性
    Java内嵌类
  • 原文地址:https://www.cnblogs.com/xiao-c-s/p/12420037.html
Copyright © 2011-2022 走看看