Using custom jar packages in springboot

    

  1. Create the springboot project    

   interface:

package pj.com.cn.myframework.register;
public interface MyPrint {
	void printDemo(String s);
}

   accomplish:

package pj.com.cn.myframework.register;
import org.springframework.stereotype.Component;
@Component
public class TestUtil implements MyPrint{
	@Override
	public void printDemo(String s) {
		System.out.println(s);
	}
}

 

 

    2. Export the project into a jar package, pay attention to check Add directory entries

 

  3. Install it to the local maven repository and run it on the command line

mvn install:install-file -Dfile=myframework.jar -DgroupId=pj.com.cn -DartifactId=myframework - Dversion=1.0 -Dpackaging=jar

  4. Create another springboot project


 

   Quote in pom:

		<dependency>
			<groupId>pj.com.cn</groupId>
			<artifactId>myframework</artifactId>
			<version>1.0</version>
		</dependency>

   Then in code:

	@Autowired
	private MyPrint util;
   
        ...
        util.printDemo("haha");
        ...

   That is to say, after the project starts, spring automatically scans the custom jar package 

 

   In addition, pay special attention to the package name structure of the two projects. This achieves the extraction of some repetitive functions into your custom "framework".

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326178546&siteId=291194637