首页 > 编程语言 >javaee spring 用注解的方式实现ioc

javaee spring 用注解的方式实现ioc

时间:2023-09-03 12:35:47浏览次数:40  
标签:4.3 plugin spring javaee springframework maven org ioc


spring 用注解的方式实现ioc

spring核心依赖

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>testSpring03</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>testSpring03 Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

    <!-- 导入spring的核心jar包 -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.3.18.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>4.3.18.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.3.18.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context-support</artifactId>
      <version>4.3.18.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-expression</artifactId>
      <version>4.3.18.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>provided</scope>
    </dependency>

  </dependencies>

  <build>
    <finalName>testSpring03</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-war-plugin</artifactId>
          <version>3.2.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

spring配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 开启注解扫描
        扫描com.test包以及所有子包中的文件
    -->
    <context:component-scan
            base-package="com.test" />
</beans>


标签:4.3,plugin,spring,javaee,springframework,maven,org,ioc
From: https://blog.51cto.com/u_15295225/7339394

相关文章

  • javaee spring jdbcTemplate的使用
    依赖<?xmlversion="1.0"encoding="UTF-8"?><projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.......
  • javaee spring 依赖注入之复杂类型的注入数组 集合 等
    spring依赖注入之复杂类型的注入packagecom.test.pojo;importjava.util.List;importjava.util.Map;importjava.util.Properties;/***@description:*@projectName:testSpring*@see:com.test.pojo*@createTime:2023/8/2714:39*/publicclassAA{pri......
  • javaee spring 依赖注入之构造方法注入
    依赖注入之构造方法注入constructor-arg标签指定构造方法的参数packagecom.test.pojo;/***@description:*@projectName:testSpring*@see:com.test.pojo*@author:杨钧博*@createTime:2023/8/2711:18*/publicclassDrink{privateStringname;pri......
  • javaee spring依赖注入之property注入
    spring依赖注入之property注入如下图,如果是基本数据类型,用value属性,如果是对象,则用ref......
  • javaee spring创建对象的三种方式
    方式一调用类的构造方法创建方法二使用静态工厂创建方法三使用非静态工厂创建......
  • javaee spring配置文件bean标签详解
    <beanid="drink_01"name="drink_02"scope="singleton"lazy-init="true"init-method="init"destroy-method="destroy"class="com.test.pojo.Drink"/>scope属性bean标签中添加......
  • Java:SpringBoot实现定时任务Scheduled
    代码示例packagecom.example.demo.config;importorg.springframework.context.annotation.Configuration;importorg.springframework.scheduling.annotation.EnableScheduling;importorg.springframework.scheduling.annotation.Scheduled;importjava.text.SimpleDate......
  • Java:SpringBoot整合SSE(Server-Sent Events)实现后端主动向前端推送数据
    SpringBoot整合SSE(Server-SentEvents)可以实现后端主动向前端推送数据目录核心代码完整代码参考文章核心代码依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>后端接收sse连接@Controller......
  • Java:SpringBoot使用AES对JSON数据加密和解密
    目录1、加密解密原理2、项目示例2.1、项目结构2.2、常规业务代码2.3、加密的实现2.4、接口测试2.5、总结1、加密解密原理客户端和服务端都可以加密和解密,使用base64进行网络传输加密方字符串->AES加密->base64解密方base64->AES解密->字符串2、项目示例2.1、项目结构$tr......
  • SpringBoot集成redis集群
    1、添加依赖<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><exclusions><!--过滤lettuce,使用jedis作为redis客户端--><exclusion&......