小编Evg*_*rov的帖子

在JSF 2.0应用程序中使用RichFaces 4

我正在尝试将RichFaces添加到JSF 2.0应用程序中,但我得到了这个: The requested resource () is not available. 那是来自Console:

java.lang.ClassNotFoundException: org.ajax4jsf.Filter
Run Code Online (Sandbox Code Playgroud)

我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>RichFaces4Test</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
  </servlet-mapping>


<!-- Plugging the "Blue Sky" skin into the project -->

<context-param>

   <param-name>org.richfaces.SKIN</param-name>

   <param-value>blueSky</param-value>

</context-param>



<!-- Making the RichFaces skin spread to standard HTML controls -->

<context-param>

      <param-name>org.richfaces.CONTROL_SKINNING</param-name>

      <param-value>enable</param-value>

</context-param>



<!-- Defining and mapping the RichFaces filter …
Run Code Online (Sandbox Code Playgroud)

java jsf richfaces

5
推荐指数
1
解决办法
2万
查看次数

在groovy bean中注入Spring bean

我有Spring-boot-starter-remote-shell的Spring Boot应用程序.当我把这个hello.groovy脚本打印出'hello'时就可以了.

package commands

import org.crsh.cli.Usage
import org.crsh.cli.Command

class hello {

    @Usage("Say Hello")
    @Command
    def main(InvocationContext context) {
        return "hello";
    }

}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试注入一些Spring bean时,它总是为null.

package commands

import org.crsh.cli.Usage
import org.crsh.cli.Command
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component
import org.springframework.batch.core.launch.JobLauncher

@Component
class hello {
    @Autowired
    JobLauncher jobLauncher;

    @Usage("Say Hello")
    @Command
    def main(InvocationContext context) {
        if(jobLauncher != null){
            return "OK";
        }else{
            return "NULL";
        }
        return "hello j";
    }

}
Run Code Online (Sandbox Code Playgroud)

我有 @ComponentScan(basePackages={"com....", "commands"})

java groovy spring

5
推荐指数
1
解决办法
1729
查看次数

Spring MVC 如何为控制器方法提供可注入性

Spring MVC 控制器方法接受在调用方法之前注入的不同参数。像HttpServletRequestHttpServletResponsejava.security.Principal等等。

@RequestMapping("/test")
public String test(HttpServletRequest req, Principal user){}
Run Code Online (Sandbox Code Playgroud)

如何声明可以在 controlelr 方法中注入的内容?

@RequestMapping("/test")
public String test(MyCustomInjectable myInjectable){}
Run Code Online (Sandbox Code Playgroud)

关于具体案例的更多信息:

我想HttpServletRequest在一些 servlet 过滤器中解析并构造一个将在控制器方法中使用的对象。更准确地说,我将解析 JWT 令牌并访问声明。

java spring dependency-injection spring-mvc spring-boot

5
推荐指数
1
解决办法
1342
查看次数

Spring Cloud Gateway 2.0 转发路径变量

如何在 Spring Cloud Gateway 2.0 中转发路径变量?

如果我们有一个微服务,它有 2 个端点:/users并且/users/{id}在端口 8080 上运行,如何将请求转发到具有 id 路径变量的端点?

以下网关配置成功转发到/users端点,但第二条路由将请求转发到/users真实服务的同一端点。

@Bean
public RouteLocator routes(RouteLocatorBuilder builder) {
    return builder.routes()
        .route("users", t -> t.path("/users").uri("http://localhost:8080/users"))
        .route("userById", t -> t.path("/users/**").uri("http://localhost:8080/users/"))
        .build();
}
Run Code Online (Sandbox Code Playgroud)

我正在使用spring-cloud-starter-gatewayspring cloudFinchley.BUILD-SNAPSHOT

java spring gateway

5
推荐指数
1
解决办法
1万
查看次数

单元测试中的Spring Boot数据源

我有一个简单的Spring Boot Web应用程序,它从数据库中读取并返回JSON响应.我有以下测试配置:

@RunWith(SpringRunner.class)
@SpringBootTest(classes=MyApplication.class, properties={"spring.config.name=myapp"})
@AutoConfigureMockMvc
public class ControllerTests {
    @Autowired
    private MockMvc mvc;
    @MockBean
    private ProductRepository productRepo;
    @MockBean
    private MonitorRepository monitorRepo;

    @Before
    public void setupMock() {
        Mockito.when(productRepo.findProducts(anyString(), anyString()))
        .thenReturn(Arrays.asList(dummyProduct()));     
    }

    @Test
    public void expectBadRequestWhenNoParamters() throws Exception {    
        mvc.perform(get("/products"))
                .andExpect(status().is(400))
                .andExpect(jsonPath("$.advice.status", is("ERROR")));
    }

    //other tests
}
Run Code Online (Sandbox Code Playgroud)

我有一个在应用程序的主配置中配置的DataSource bean.当我运行测试时,Spring尝试加载上下文并失败,因为数据源来自JNDI.一般情况下,我想避免为此测试创建数据源,因为我已经模拟了存储库.

在运行单元测试时是否可以跳过数据源的创建?

在内存数据库中进行测试不是一个选项,因为我的数据库创建脚本具有特定的结构,并且无法从类路径中轻松执行:schema.sql

编辑 数据源定义于MyApplication.class

    @Bean
    DataSource dataSource(DatabaseProeprties databaseProps) throws NamingException {
       DataSource dataSource = null;
       JndiTemplate jndi = new JndiTemplate();
       setJndiEnvironment(databaseProps, jndi);
       try {
           dataSource = jndi.lookup(databaseProps.getName(), DataSource.class);
       } catch …
Run Code Online (Sandbox Code Playgroud)

java spring unit-testing mockito spring-boot

5
推荐指数
2
解决办法
9601
查看次数

Spring Data JDBC是否支持自定义类型转换器

我有一个实体,该实体的文件类型为java.util.Date(或Timestamp,与大小写无关)。

public class StatusReason {
    @Column("SRN_ID")
    private Long id;
    @Column("SRN_CREATOR")
    private String creator;
    @Column("SRN_REASON")
    private String reason;
    @Column("SRN_STATUS")
    private String status;
    @Column("SRN_TIMESTAMP")
    private Date timestamp;
//getters, setters, etc...
}
Run Code Online (Sandbox Code Playgroud)

数据库是Oracle,相应的列是类型 TIMESTAMP(6) WITH TIME ZONE

当我调用存储库的任何默认值findByIdfindAll方法时,都会得到: ConverterNotFoundException: No converter found capable of converting from type [oracle.sql.TIMESTAMPTZ] to type [java.util.Date]

我可以RowMapper为该类型创建一个自定义,它将正常工作。我只是想知道是否可以注册一个自定义转换器(在我的情况下为oracle.sql.TIMESTAMPTZto java.util.Date),因此仍然可以从默认映射中受益,并在整个应用程序中使用该转换器。

java oracle spring-data-jdbc

5
推荐指数
1
解决办法
887
查看次数

Spring 2.5无法获得JDBC连接

我正在使用spring 2.5 SimpleJdbcTemplate来访问MySQL数据库.当我尝试经常访问数据库(使用Quartz每分钟访问它)时,我得到了这个堆栈跟踪:

org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Communications link failure

The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.)
    at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82)
    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:382)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:458)
    at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:466)
    at org.springframework.jdbc.core.JdbcTemplate.queryForList(JdbcTemplate.java:497)
    at org.springframework.jdbc.core.simple.SimpleJdbcTemplate.queryForList(SimpleJdbcTemplate.java:223)
    at com.db.timexis.dao.UserDaoJdbc.getListOfAllUsers(UserDaoJdbc.java:137)
    at com.db.timexis.service.AuthServiceImpl.getListOfAllUsers(AuthServiceImpl.java:77)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) …
Run Code Online (Sandbox Code Playgroud)

java mysql spring apache-commons-dbcp

4
推荐指数
1
解决办法
2万
查看次数

KnockoutJS Observables的Observable对象

我想制作可观察的可观察对象.例如:

        var Project = function(id, name, custId) {
            this.id = ko.observable(id);
            this.name = ko.observable(name);
            this.custId = ko.observable(custId);
        }

        var viewModel = function() {

                    this.newUpProj = ko.observable(new Project(null,null,null));
            ...
            }
Run Code Online (Sandbox Code Playgroud)

像这样的东西......我想要newUpProject观察它,它的属性是可观察的.我也试过了this.newUpProj = ko.mapping.fromJS(new Project());

Edit1:它包装对象,但它的属性(id,name ...)不是可观察的...

Edit2:在html中使用:

<div class="modal-body">
                <p><input type="text" id="projNameTx" data-bind="value: newUpProj.name()" /></p><br>
                <p><select data-bind="options: customers, optionsCaption: 'Choose...', value: newUpProj.custId(), optionsText: 'name', optionsValue: 'id'" 
                    size="1"></select></p>

            </div>
            <div class="modal-footer">
                <button class="btn" data-bind="click: clearModal" aria-hidden="true">Close</button>
                <button class="btn btn-primary" data-bind="click: updateFlag() ? updateProject : addProject, enable: newUpProj.custId() && newUpProj.name()">Save</button> …
Run Code Online (Sandbox Code Playgroud)

javascript knockout.js

4
推荐指数
2
解决办法
1万
查看次数

Spring MVC @RequestBody如何工作

我认为@RequestBody尝试params通过属性名称在注释之后将请求映射到对象.

但如果我得到:

@RequestMapping(value = "/form", method = RequestMethod.GET)
public @ResponseBody Person formGet(@RequestBody Person p,ModelMap model) {
    return p;
}
Run Code Online (Sandbox Code Playgroud)

请求:

http://localhost:8080/proj/home/form?id=2&name=asd
Run Code Online (Sandbox Code Playgroud)

返回415

当我改变@RequestBody Person p@RequestParam Map<String, String> params,没关系:

@RequestMapping(value = "/form", method = RequestMethod.GET)
public @ResponseBody Person formGet(@RequestParam Map<String, String> params) {
        return new Person();
}
Run Code Online (Sandbox Code Playgroud)

人员类:

public class Person{
    private long id;
    private String name;

    public Person() {
    }

    public Person(long id, String name) {
        super();
        this.id = id;
        this.name = …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

4
推荐指数
1
解决办法
8802
查看次数

Spring AspectJ 从 ProceedingJoinPoint 获取方法注解

我有一个方面可以处理所有具有自定义注释的方法。

注释有一个枚举参数,我必须在方面获取值:

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Monitored {
    MonitorSystem monitorSystem();
}
Run Code Online (Sandbox Code Playgroud)

我的情况与那个问题非常相似,接受的答案适用于未实现接口的 Spring bean。

方面:

@Aspect
@Component
public class MonitorAspect {

    @Around("@annotation(com.company.project.monitor.aspect.Monitored)")
    public Object monitor(ProceedingJoinPoint pjp) throws Throwable {
        MethodSignature signature = (MethodSignature) pjp.getSignature();
        MonitorSystem monitorSystem = signature.getMethod().getAnnotation(Monitored.class).monitorSystem();
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

但是如果被注解的 Spring bean @Monitored(只有实现类被注解)实现了一个接口 -pjp.getSignature()返回接口的签名并且它没有注解。

还行吧:

@Component
public class SomeBean {
   @Monitored(monitorSystem=MonitorSystem.ABC) 
   public String someMethod(String name){}
}
Run Code Online (Sandbox Code Playgroud)

这不起作用 - pjp.getSignature() 获取接口的签名。

@Component
public class SomeBeanImpl implements SomeBeanInterface {
   @Monitored(monitorSystem=MonitorSystem.ABC) 
   public String someMethod(String name){}
} …
Run Code Online (Sandbox Code Playgroud)

java spring annotations aspectj aspect

4
推荐指数
2
解决办法
4432
查看次数