简体   繁体   English

Spring-JDBC作为独立库

[英]Spring-JDBC as standalone library

I have a small application that doesn't use Spring container. 我有一个不使用Spring容器的小应用程序。 Now there's a need for this application to access a database, just several small queries, nothing complex. 现在需要这个应用程序访问数据库,只需几个小查询,没什么复杂的。 Although I can do this with pure JDBC I'd really like to utilize Spring-JDBC library. 虽然我可以用纯JDBC做到这一点,但我真的很想使用Spring-JDBC库。 My concern is whether it can be easily used without bringing in too much Spring into the application. 我担心的是,如果不将太多的Spring引入应用程序,它是否可以轻松使用。 By "too much Spring" I mean having to create spring containers, excessive external library dependencies, etc. Please, advise. “太多的春天”我的意思是必须创建弹簧容器,过多的外部库依赖等。请建议。

I think you have to have the Spring core JAR and its dependencies, but you're never required to use the bean factory if you don't want to. 我认为你必须拥有Spring核心JAR及其依赖项,但如果你不愿意,你永远不需要使用bean工厂。 Sounds like all you want is the JdbcTemplate . 听起来你想要的就是JdbcTemplate If that's the case, I'd put the spring-jdbc JAR into my CLASSPATH , build, and keep adding JARs until all the ClassNotFoundExceptions went away. 如果是这种情况,我会将spring-jdbc JAR放入我的CLASSPATH ,构建并继续添加JAR,直到所有ClassNotFoundExceptions消失。 That would be the minimum set you'd need to use Spring JDBC on its own. 这将是您自己使用Spring JDBC所需的最小集合。

I'd put Spring JDBC dependency into my project, for example, in case of Apache Ivy: 我将Spring JDBC依赖项放入我的项目中,例如,在Apache Ivy的情况下:

<dependency org="org.springframework" name="org.springframework.jdbc" rev="3.0.4.RELEASE" conf="src,runtime->runtime"/>

It would resolve all other required dependencies for me. 它将为我解决所有其他所需的依赖项。

If you look at the dependency list in SprinSource Enterprise Bundle Repository , you'll see that it requires Core, Beans and Context. 如果查看SprinSource Enterprise Bundle Repository中的依赖项列表,您将看到它需要Core,Beans和Context。 You can't get rid of that. 你无法摆脱这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM