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

  • 相关阅读:
    开始制作国产的 scratch
    七个对我最重要的职业建议(译文)
    不要在功能上竞争
    来看看机智的前端童鞋怎么防盗
    悬疑塑成天才?
    Linux常用命令之重启关机命令
    Linux常用命令之网络命令
    Linux常用命令之文件搜索命令
    Linux常见命令之权限管理命令
    Linux常见命令之文件处理命令
  • 原文地址:https://www.cnblogs.com/xiao-c-s/p/12420037.html
Copyright © 2011-2022 走看看