JAVASPRING - 技术教程文章

java-Spring AOP,切入点表达式:具有特定参数的注释【代码】

我有使用方法clear()的Aspect类.@Aspect public class Clear {@After("@annotation(org.springframework.transaction.annotation.Transactional)") public void clear() { // do smth } } 现在我想在每次执行带有注解@Transactional的方法后使用readOnly = true调用此方面@Transactional(readOnly = true) public void someMethod() { //... } 有没有自定义注释的方法?解决方法:我觉得你很亲密. 在您的clear方法中,...

java-Spring容器XML配置参考可以使用另一个bean的属性吗【代码】

在这里我正在编写一个spring应用程序,在这里我想做的是这样的:<bean id="sqlClient" class="com.braoda.dao.sqclient.SqlclientWapper"><property name="dataSource" ref="dataSource"/></bean><bean id="userDao" class="com.braoda.dao.user.UserDaoImpl"><property name="sqlSession" ref="***sqlClient.SqlSessionFactoryBean***" />就像代码一样,我想使用“ ref”中的spring Xml属性配置,但是“ ref”不是bean,而是bean的属...

java springboot poi 从controller 接收不同类型excel 文件处理【代码】【图】

根据poi接收controller层的excel文件导入 可使用后缀名xls或xlsx格式的excel。 1.pom引入 <!-- poi 操作Excel --><dependency><groupId>org.apache.poi</groupId><artifactId>poi</artifactId><version>3.17</version></dependency><dependency><groupId>org.apache.poi</groupId><artifactId>poi-ooxml</artifactId><version>3.17</version></dependency>2.ExcelImportUtil 工具类创建  import com.guard.biz.comm...

java-spring.web服务在web.xml中的配置?【代码】

我正在使用spring-ws,并且我的web.xml中具有以下配置<servlet><servlet-name>spring-ws</servlet-name><servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class><init-param><param-name>**transformWsdlLocations**</param-name><param-value>true</param-value></init-param></servlet><servlet-mapping><servlet-name>spring-ws</servlet-name><url-pattern>/*</url-pattern></servlet-...

java-Spring-多个方面顺序混乱【代码】

我无法按特定顺序启动多个方面.我正在使用RequestProcessor在控制器上的每个传入请求上执行某些操作,这些请求具有特定的参数 然后,我将添加一些特定的注释,这些注释将仅添加到控制器中的某些方法. 仅供参考,我在基于Java /注释的配置中使用Eclipse,Tomcat,Maven和spring.我使用Tomcat和WebApplicationInitializer加载上下文,调度程序,侦听器等.我没有web.xml.如果需要,我也可以发布该文件或pom.xml. 我得到的问题是,即使指定了顺序...

java-Spring Security匿名用户已访问每个URL【代码】

我正在开发想要使用spring-security进行保护的gwt应用程序.我在数据库中有用户数据,并且UserService负责获取特定的User.我关注了这个tutorial AuthenticationProvider:public class CustomAuthenticationProvider implements AuthenticationProvider {@Autowired UserService userService;@Overridepublic Authentication authenticate(Authentication authentication) throws AuthenticationException {String username = (Strin...

Java-Spring MVC:在两个JSPS之间导航的最佳实践【代码】

我正在使用spring mvc spring security构建一个简单的Web应用程序.我实现了登录/注销(spring mvc),但是我还想提供一个可直接从login.jsp访问的注册jsp.基本上,我只需要从login.jsp到regsiter.jsp的简单链接,而无需传递任何参数或其他任何参数.我只想问你实现这一目标的最佳实践是什么? 有什么方法可以直接在两个jsps之间导航,而无需将请求向下路由到控制器? (或者这不是Spring MVC的真正方法吗?)说实话,我唯一的“问题”是在寄存...

java-Spring Controller覆盖@ModelAttribute请求参数映射【代码】

假设我有一个像这样的Spring Controller:@Controllerpublic class FooController {@RequestMapping(value = "/foo", method = RequestMethod.GET)public String update (Model model,@RequestParam (value="id") String id,@RequestParam (value="description") String description) {Foo foo = new Foo(id, description);fooService.create(update);return "foo";}我想像下面这样重写它,但是定义我自己的请求参数映射而不是让Spr...

java-Spring RequestParam地图【代码】

我的控制器中有这个:@RequestMapping(value = "/myUrl", method = RequestMethod.GET) public String myUrl(@RequestParam(value = "test") Map<String, String> test) {return test.toString(); }我正在发出此HTTP请求:GET http://localhost:8080/myUrl?test[a]=1&test[b]=2但是在日志中,我收到此错误:org.springframework.web.bind.MissingServletRequestParameterException: Required Map parameter 'test' is not present如...

java-Spring-JDBC batchUpdate不提交更改.这是一个臭虫吗?【代码】

我正在研究的项目使用以下依赖项<dependency><groupId>org.springframework</groupId><artifactId>spring-jdbc</artifactId><version>3.2.0.RELEASE</version></dependency>我正在使用以下方法调用(1)template.batchUpdate(INSERT_SQL, instance of BatchPreparedStatementSetter);查看Spring JDBCTemplate中的源代码,似乎(因为驱动程序支持批处理更新)PreparedStatement上的executeBatch()被调用.但是,我看不到数据库中更新的影响...

java-Spring Batch和Spring Integration的集成问题-“未为端点定义轮询器”异常【代码】

我经历了Spring Integration guide和examples here,并获得了Spring Integration SFTP程序的工作样本.我已经有一个运行中的Spring Batch程序,该程序可以读取一堆文件并将其转储到数据库中. 我现在正在尝试通过Spring docs来集成Spring Batch和Spring Integration程序,并创建了以下配置.<bean id="sftpSessionFactory" class="org.springframework.integration.sftp.session.DefaultSftpSessionFactory"><property name="host" value...

java-Spring Tool Suite应用程序上下文xml错误,即使所有bean似乎都可以正常工作【代码】

我正在Spring应用程序上下文xml之一中配置jpa和jpa存储库. 如果我同时拥有< jpa:repositories base-package =“ ...” />和< context:component-scan base-package =“ ...” />然后Spring Tool Suite在第1行显示错误 引用的文件包含错误(http://www.springframework.org/schema/context/spring-context-4.0.xsd).有关更多信息,请右键单击 问题视图,然后选择“显示详细信息…” 在单击显示详细信息后,我得到以下信息:The errors...

java-Spring MVC处理会话已过期【代码】

我正在使用Jboss EAP 6.2,Java EE 6和Spring MVC 4.0.2.当会话过期时,我要执行页面重定向. 我已经开发了弹簧拦截器@Component public class SessionExpiredInterceptor extends HandlerInterceptorAdapter {static final Logger logger = Logger.getLogger(SessionExpiredInterceptor.class);@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {fin...

java-Spring MVC 3.2.5无法识别的字段Jackson【代码】

我将Spring MVC升级到Spring 3.2.5.我的一些剩余调用即使存在,也会返回无法识别的字段异常.这是错误.Resolving exception from handler [public com.app.common.web.datatables.DataTablesAjaxResponse<com.app.cms.consultation.dto.ActiveMedicationView> com.app.cms.consultation.controller.impl.ActiveMedicationControllerImpl.ajaxSearchActiveMedication(java.lang.String,com.app.common.web.datatables.DataTablesAjaxR...

java-Spring JPA / Hibernate org.hibernate.AssertionFailure:实体中的null id(发生异常后不要刷新Session)【代码】

专家/大师/朋友 我们的应用程序可与Spring 3.2,JPA 2,Hibernate 4.2技术堆栈以及MySQL& Tomcat7.我们得到一个奇怪的异常,这是一个很棘手的难题.我们有一个非常简单的实体,可以通过Junit测试正常运行,没有任何问题.但是,当我添加HibernateEmptyInterceptor(在此处移动了公司的通用逻辑)时,我得到了以下提到的异常.或者,我什至尝试使用Hibernate PreInsertEventListener也是相同的异常. 在阅读了stackoverflow中的几篇文章-this、thi...

java-Spring MVC作为REST提供程序,使用AngularJS与Web层的JSP / Velocity / Freemarker

默认情况下,Spring MVC的创建者建议使用JSP或模板引擎之一(Freemarker,Velocity)来提供Web层. 另一方面,JavaScript框架的支持者可能会建议仅将Spring MVC用作REST / WS服务提供者,并将服务层与将在其中一个JS框架(例如Angular JS)中创建的Web层完全分离. 与前一种解决方案相比,后一种解决方案是否有任何缺点?现在是否将其中一种方法视为最新的行业标准?解决方法:是的,与前者相比,后者有一个缺点,仅在于通过使用后者,您可以将应用...

Java-Spring Boot-Tomcat JNDI在服务bean中失败【代码】

我正在尝试在Spring Boot 1.1.6 Web项目中将数据源从c3p0切换到Tomcat JNDI.我在GitHub中找到了一个示例应用程序,当从@RestController注释类访问DataSource实例时,它可以正常工作.@RestController public class TestController {@Autowiredprivate DataSource dataSource;@RequestMapping("/test")@ResponseBodypublic String test() {// Gets object instance... everything is OK...System.out.println(this.dataSource); }但是,...

java-Spring ClientInterceptor在响应中显示空的SOAP标头【代码】

我有一个需要与之交谈的SOAP服务.第一个SOAP请求在SOAP标头中收到带有sessionID元素的响应,我需要在最终发布命令中发送该响应. 要获取此sessionID值,我计划使用ClientInterceptor.在实现WebServiceGatewaySupport的过程中,我注册了拦截器:this.setInterceptors(new ClientInterceptor[] { new MyWebServiceClientInterceptor() });我的拦截器:public class MyWebServiceClientInterceptor implements ClientInterceptor {public ...

java-Spring Boot向环境添加另一个属性文件【代码】

我想知道是否有可能仅将application.properties文件添加到环境路径中.如果是这样,您如何指定新路径?因此,您可以使用Autowired Environment变量访问属性.当前在我的Java项目中,默认属性文件application.properties的路径为/soctrav/src.main.resources/application.properties解决方法:您可以使用命令行参数指定其他属性文件:java -jar myproject.jar --spring.config.location=classpath:/default.properties,classpath:/overrid...

java-spring jdbc模板和最好的模板使用

我的问题是关于哪个jdbc模板必须最常用,以及使用简单的jdbc模板(尽管它既可以用于命名占位符又可以用于问号占位符)有什么缺点,基本上可以说明我的区别以及是最好的,因为我是spring框架的新手.解决方法:JdbcTemplate类执行SQL查询,更新语句和存储过程调用,对ResultSet执行迭代并提取返回的参数值.它还捕获JDBC异常,并将其转换为org.springframework.dao包中定义的通用,信息量更大的异常层次结构. 一旦配置,JdbcTemplate类的实例是线...

java-Spring参考文档中的C-namespace部分

我正在阅读春季文件,但我无法理解以下c-namespace section in the reference document的声明For the rare cases where the constructor argument names are not available (usually if the bytecode wascompiled without debugging information), one can use fallback to the argument indexes我的问题是: >在什么情况下,构造函数参数不可用.>编译无调试信息的字节码是什么意思.可以使用eclipse检查吗? 我正在通过Web检查此内容...

java-Spring Tool Suite入门指南不起作用【代码】

我正在尝试使用Spring Tool Suite(STS)(版本:3.6.3.RELEASE)来做“使用STS入门指南”(在这里:http://spring.io/guides/gs/sts/),并且在“导入入门内容”向导中没有文件菜单.我尝试导入“ Spring入门内容”,它说它是空的. 我只想浏览链接中的教程.解决方法:在窗口上配置代理设置->首选项->网络连接将模式更改为“手动”,启用https,设置代理主机和凭据. 然后将默认的Apache httpclient提供程序(由Eclipse更新使用)更改为基于JRE UR...

java-Spring安全角色层次结构不适用于Thymeleaf sec:authorize【代码】

我正在将Spring Security 3.2.5.RELEASE与ThymeLeaf 2.1.4.RELEASE一起使用.我已经在安全上下文中定义了角色层次结构.在我的视图层中,我使用sec:authorize属性定义菜单项.我希望看到所有在顶级角色下的菜单项,但我只会看到在该角色下定义的菜单.如何解决此问题,以便在顶层下查看所有菜单? 任何指针将不胜感激.谢谢.<beans:bean id="roleVoter" class="org.springframework.security.access.vote.RoleHierarchyVoter"><beans:cons...

java-Spring 4 RestController:未从PUT请求接收数据【代码】

我正在尝试使用Spring构建一个非常基本的REST API. 我的URL端点是:GET /notes GET /notes/{noteId} POST /notes PUT /notes/{noteId} DELETE /notes/{noteId}除了我要运行以更新项目的PUT请求之外,所有这些端点都可以按预期正常工作. 问题是数据没有通过PUT接收,因为它对POST正常工作. 这是我的控制器;我已经通过添加与update方法相同但使用POST的方法进行了测试,并且效果很好.不知道为什么package notes;import org....

java-Spring 4中的DeferredResult支持Servlet 3.1(Read | Write)Listener吗?【代码】

我正在阅读JayWay article关于Spring上Servlet的异步支持. 有趣的部分是:If your service is expected to receive large request or response bodies, especially if the clients write or read slowly, you would benefit from using the non-blocking IO feature introduced in Servlet 3.1, as mentioned earlier. On the ServletInputStream there is the method setReadListener where you can set a ReadListener.我看到您可...

java-Spring 4:FactoryBean <>实例上的MethodInvokingFactoryBean【代码】

我正在尝试使用org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean在Spring 4中创建FreeMarker配置,然后自定义生成的freemarker.template.Configuration(以更改算术引擎). 我正在使用以下XML配置(简化):<bean id="freemarkerConfiguration" class="org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean"><property name="templateLoaderPaths">...</property>... </bean><bean class="org....

java-Spring MVC中的StreamingOutput等效项【代码】

我在Spring Boot中创建了一个Web应用程序,在其中我想使用Spring MVC rest框架而不是jersey.我正在尝试做这样的事情,但这给了我错误.我想要等效于Spring MVC中的StreamingOutput. 例如:这使用JAX-RS StreamingOutputpublic static StreamingOutput buildErrorEntity(Object error) {StreamingOutput stream = outputStream -> {PrintStream printStream = new PrintStream(outputStream);new ObjectMapper().writeValue(printStrea...

java-Spring Integration-应用程序代码中的调用方法【代码】

我有一个outbound-channel-adapter,其相关配置如下所示.<int:outbound-channel-adapter channel="foo-fileChannel" ref="foo-handlerTarget" method="handleFeedFile"><int:poller fixed-delay="5000" receive-timeout="1000" max-messages-per-poll="10" /> </int:outbound-channel-adapter> <int:channel id="foo-fileChannel"><int:queue /> </int:channel><bean id="foo-handlerTarget" class="com.abc.FooFeedHandlerImpl"><p...

java-Spring寄存器对象销毁方法【代码】

我目前正在将XML spring config转换为Java注释,并且遇到了一些烦人的情况. 我需要创建3个bean,它们在内部使用相同的类,但需要是单独的实例.但是,这些内部bean需要在Spring中注册其关闭方法. 我不认为如何在Java中不创建9个bean的情况下做到这一点(很好,但是污染这样的类似乎有点不对劲) 在XML配置中,它看起来像这样:<bean class="outer1"><constructor-arg><bean class="middle"><constructor-arg><bean class="inner" /></constr...

java-Spring / Hibernate-实体被隐式持久化【代码】

在以下代码中,CustomerService.test()方法隐式保留了客户对象,即,没有任何对merge()或update()的调用.为什么会发生这种情况,并且仅当我明确调用merge / update时,才能强制它持久化实体? 控制器:@Controller @RequestMapping("/samples") public class Samples {@Autowiredprivate CustomerService customerService;@RequestMapping(value = "/test", method = RequestMethod.GET)@ResponseBodypublic String test(){customerServ...