本文将为您提供关于Java如何在SpringWs中处理证书?的详细介绍,我们还将为您解释springjavaweb的相关知识,同时,我们还将为您提供关于java–Spring:如何在Spring配置中
本文将为您提供关于Java如何在Spring Ws中处理证书?的详细介绍,我们还将为您解释spring javaweb的相关知识,同时,我们还将为您提供关于java – Spring:如何在Spring配置中注入ENUM?、java – 如何在spring中提供测试数据源?、java – 如何在Spring中池对象?、java – 如何在Spring事务中获得连接?的实用信息。
本文目录一览:- Java如何在Spring Ws中处理证书?(spring javaweb)
- java – Spring:如何在Spring配置中注入ENUM?
- java – 如何在spring中提供测试数据源?
- java – 如何在Spring中池对象?
- java – 如何在Spring事务中获得连接?
Java如何在Spring Ws中处理证书?(spring javaweb)
我需要使用Spring Ws使用Web Service。我正在使用WEB服务模板。我需要知道,仅在java
keystore和trustore中指定证书,证书的发送和接收会自动发生吗?如果密钥库和信任库配置正确或者我必须编写一些代码,服务器证书的验证也会在Spring
Ws中自动进行吗?如果不是,我如何在Spring WS中发送和接收证书?
答案1
小编典典一旦你选择了安全拦截器,你喜欢用。假设您已准备好所有证书,则可以按照下面的链接为每个安全拦截器设置一种或两种方式的ssl。该链接不是最新的,但可以帮助您入门。
XwsSecurityInterceptor
服务器安全设置
客户端安全设置
Wss4jSecurityInteceptor
客户端和服务器安全设置
java – Spring:如何在Spring配置中注入ENUM?
package com.myorg.sparrow.s3Environment; import javax.annotation.Nonnull; public enum DocumentType { Document("document/",".xml.gz","binary/octet-stream","gzip",true); private final String path; private final String suffix; private final String contentType; private final String contentEncoding; private final Boolean compress; private DocumentType(@Nonnull final String path,@Nonnull final String suffix,@Nonnull final String contentType,@Nonnull final String contentEncoding,@Nonnull final Boolean compress) { this.path = path; this.suffix = suffix; this.contentType = contentType; this.contentEncoding = contentEncoding; this.compress = compress; } @Nonnull public String getPath() { return path; } @Nonnull public String getSuffix() { return suffix; } @Nonnull public String getContentType() { return contentType; } @Nonnull public String getContentEncoding() { return contentEncoding; } @Nonnull public Boolean isCompress() { return compress; } }
我想在Spring配置文件中注入DocumentType.Document的这个值
<bean id="s3Service"https://www.jb51.cc/tag/nes/" target="_blank">ness.xml.persist.S3Service"> <constructor-arg ref="awsCredentials" /> <constructor-arg value="**DocumentType.DOCUMENT**" /> // how do I inject it here? <constructor-arg value="${com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator-destBucketName}" /> </bean>
我如何注入此值
<constructor-arg value="**DocumentType.DOCUMENT**" /> // how do I inject it here?
我是Spring框架的新手,不知道如何实现这一点
谢谢
解决方法
<bean id="s3Service"https://www.jb51.cc/tag/nes/" target="_blank">ness.xml.persist.S3Service"> <constructor-arg ref="awsCredentials" /> <constructor-arg value="Document" /> // We love Spring because it is simpler than we expect <constructor-arg value="${com.myorg.sparrow.s3EnvironmentConfiguration.S3EnvironmentConfigurator-destBucketName}" /> </bean>
java – 如何在spring中提供测试数据源?
我现在正在用Hibernate学习Spring.我有一个POJO模型类,注释了Hibernate注释,称为Person,PersonDao接口,它是hibernate实现和PersonService类.我正在使用注释,因此我们的spring-config.xml中没有将它们定义为bean.现在我想为我的PersonService类编写一些JUnit4测试,但我想在测试时使用不同的数据库.这是我的spring-config.xml
MysqL.jdbc.Driver" />
MysqL://localhost/example" />
factorybean">
MysqLDialectsql">true
我想在我的测试中使用jdbc:MysqL:// localhost / example_test数据库.我如何实现这一目标?
最佳答案
>将jdbc:MysqL:// localhost / example移动到配置文件(db.properties)
database.uri = JDBC:MysqL的://本地主机/示例
>将此文件放在classpath中的某个位置(即src / main / resources)
>在Spring上下文中设置属性占位符并使用数据库URI属性键
sspath:db.properties" />
...
>在测试类路径中创建具有相同名称的配置文件(src / test / resources)
>将数据库URI属性更改为测试值(jdbc:MysqL:// localhost / example_test)
database.uri = JDBC:MysqL的://本地主机/ example_test
利润
java – 如何在Spring中池对象?
我怎么可能做错了?我是否误解了Spring中汇集的概念?
以下是我的代码:
应用程序上下文:(这只是我的应用程序上下文的主体.)
<bean id="simpleBeanTarget"scope="prototype"> </bean> <bean id="poolTargetSource"> <property name="targetBeanName" value="simpleBeanTarget" /> <property name="maxSize" value="2" /> </bean> <bean id="simpleBean"https://www.jb51.cc/tag/factorybean/" target="_blank">factorybean"> <property name="targetSource" ref="poolTargetSource" /> </bean>
控制器:(这只是我方法的主体)
@RequestMapping("/hello") public ModelAndView helloWorld(HttpServletRequest request,HttpServletResponse response) { String message = "Hello World,Spring 3."; try { System.out.println("Accessing Application Context"); ApplicationContext context = new ClasspathXmlApplicationContext("applicationContext.xml"); System.out.println("Getting Bean"); SimpleBean simpleBean = (SimpleBean) context.getBean("simpleBean"); //A new SimpleBean... is printed here. System.out.println("displaying Hello World: " + simpleBean.getRandomNum()); //After this line,A new SimpleBean... is printed again. I simply access the getter method. Why does it create a new instance of SimpleBean? return new ModelAndView("hello","message",message); }catch(Exception e) { System.out.println("Error: " + e); e.printstacktrace(); return new ModelAndView("hello","Error! " + e.getMessage()); } }
我正在汇集的bean:
package com.bean; import java.util.Random; public class SimpleBean { int randomNum; String str; SimpleBean() { Random randomGenerator = new Random(); randomNum = randomGenerator.nextInt(100); //I'm printing this line just to check if a instance of this bean is created. System.out.println("#####################A new SimpleBean was born: " + randomNum); str = "This is a string."; } public int getRandomNum() { return randomNum; } public void setRandomNum(int randomNum) { this.randomNum = randomNum; } public String getstr() { if (str == null) return "str is null"; return str; } public void setStr(String str) { this.str = str; } }
我的web.xml的正文:
<display-name>Spring3MVC</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/classes/applicationContext.xml</param-value> </context-param> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>spring</servlet-name> <servlet-class> org.springframework.web.servlet.dispatcherServlet </servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping>
解决方法
web.xml中的引用片段
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:spring/appContext.xml classpath*:spring/appContext-security.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
看你的代码:
try { System.out.println("Accessing Application Context"); ApplicationContext context = new ClasspathXmlApplicationContext("applicationContext.xml"); ...
有关Spring上下文加载的更多信息,请参阅MKyong ‘s tutorial或Spring reference
java – 如何在Spring事务中获得连接?
想象一下这段代码:
foo() {
Connection conn = ...;
}
已从具有注释@Transactional的方法调用foo().如何获取当前的JDBC连接?请注意,foo()在bean中(因此它可以有@Autowired字段)但foo()不能有参数(因此我无法从某处传递连接).
[编辑]我正在使用需要数据源或连接的jOOQ.我的问题:我不知道配置了哪个事务管理器.它可能是任何东西; Java EE,基于DataSource,通过JNDI获取数据源.我的代码不是应用程序,它是一个库.我需要吞下别人放在盘子里的东西.同样,我不能请求Hibernate会话工厂,因为使用我的应用程序可能不会使用Hibernate.
但我知道其他代码,如Spring Hibernate集成,不知何故可以从事务管理器获取当前连接.我的意思是,Hibernate不支持Spring的事务管理器,因此粘合代码必须使Spring API适应Hibernate所期望的.我需要做同样的事情,但我无法弄清楚它是如何工作的.
[EDIT2]我知道有一个活动事务(即Spring在某个地方有一个Connection实例,或者至少有一个事务管理器可以创建一个),但我的方法不是@Transactional.我需要调用一个构造函数,它将java.sql.Connection作为参数.我该怎么办?
事务管理器与数据源完全正交.一些事务管理器直接与数据源交互,一些通过中间层(例如,Hibernate)交互,一些交互管理器通过容器提供的服务(例如,JTA)进行交互.
当你将方法标记为@Transactional时,所有这意味着Spring将在加载bean时生成代理,并且该代理将被传递给任何其他想要使用bean的类.当调用代理的方法时,它(代理)要求事务管理器为其提供未完成的事务或创建新的事务.然后它调用你的实际bean方法.当bean方法返回时,代理再次与事务管理器交互,要么说“我可以提交”,要么“我必须回滚”.这个过程有些曲折;例如,事务方法可以调用另一个事务方法并共享同一个事务.
当事务管理器与DataSource交互时,它不拥有DataSource.您不能要求事务管理器为您提供连接.相反,您必须注入一个将返回连接的特定于帧的对象(例如Hibernate SessionFactory).或者,您可以使用静态事务感知实用程序类,但这些类又与特定框架相关联.
我们今天的关于Java如何在Spring Ws中处理证书?和spring javaweb的分享已经告一段落,感谢您的关注,如果您想了解更多关于java – Spring:如何在Spring配置中注入ENUM?、java – 如何在spring中提供测试数据源?、java – 如何在Spring中池对象?、java – 如何在Spring事务中获得连接?的相关信息,请在本站查询。
本文标签: