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

  • 相关阅读:
    XAMPP配置8080端口
    Composer安装使用
    .Net商品管理(注释,百度,提问,对比,总结)
    .Net数据库操作
    VS链接数据库
    .Net中字典的使用
    一套解决方案,多个项目
    转化一下解决问题的思路,弯道超车
    灵活的运用Model类
    Razor数组数据
  • 原文地址:https://www.cnblogs.com/xiao-c-s/p/12420037.html
Copyright © 2011-2022 走看看