[英]Create a Spring Framework starter project, not Spring Boot
I'm working on a project that uses Spring Framework 3.2.11.RELEASE
version and we want to implement some new stuff in it, but before I want to make a small Rest API so I can do a proof of concept application.我正在开发一个使用 Spring Framework
3.2.11.RELEASE
版本的项目,我们想在其中实现一些新的东西,但在我想做一个小 Rest ZDB974238714CA8DE634A7CE10 概念应用程序之前可以做一个证明。 This small Rest API must use the same packages as the original one (no, updating the main project is not an option).这个小 Rest API 必须使用与原版相同的包(不,不能更新主项目)。
When using https://start.spring.io/ it gives me a good project but using Spring boot, which is not what I want.当使用https://start.spring.io/时,它给了我一个很好的项目,但使用 Spring 引导,这不是我想要的。 Using the project Initialzr gave me I changed the
pom.xml
to use the same spring packages of the original project:使用 Initialzr 给我的项目,我将
pom.xml
更改为使用与原始项目相同的 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project </description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.2.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.2.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.11.RELEASE</version>
</dependency>
</dependencies>
</project>
Now I'm trying to modify the starter class to work with the dependencies in the pom.xml
.现在我正在尝试修改启动器 class 以使用
pom.xml
中的依赖项。 This is where I'm lost, so far I couldn't find anything similar in the main project or the web.这就是我迷路的地方,到目前为止,我在主项目或 web 中找不到类似的东西。 So, how could I change this main class so I can get it working?
那么,我怎样才能改变这个主要的 class 让它工作呢?
package com.example.demo;
import org.springframework.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
If you haven't added any BusinessLogic to your current SpringBoot
application, then you can create new Spring project using Eclipse
or STS
IDE.如果您尚未向当前的
SpringBoot
应用程序添加任何 BusinessLogic,则可以使用Eclipse
或STS
IDE 创建新的 Spring 项目。 Your tester or main class will look something like this:您的测试仪或主 class 将如下所示:
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
public class Test {
public static void main(String[] args) {
Resource resource=new ClassPathResource("applicationContext.xml");
BeanFactory factory=new XmlBeanFactory(resource);
Student student=(Student)factory.getBean("studentbean");
student.displayInfo();
}
}
(I have Student
class created in my IDE that's why using an instance of that class just for DEMO) And your .xml
file should look like this: (I have
Student
class created in my IDE that's why using an instance of that class just for DEMO) And your .xml
file should look like this:
<?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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="studentbean" class="com.app.Student">
<property name="name" value="Student1"></property>
</bean>
</beans>
I hope this will somehow help you!我希望这会以某种方式帮助你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.