<?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" 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>RestfulService</display-name>
<!-- <welcome-file-list>
<welcome-file>Readme.html</welcome-file>
<welcome-file>index.html</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>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.restfulservice.gateway</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ApplicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- <bean
class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> -->
<context:component-scan base-package="com.restfulservice" />
<context:annotation-config/>
<!-- <context:property-placeholder location="classpath:testme.properties" /> -->
<bean id="incomingCall" class="com.restfulservice.gateway.IncomingCall" />
<bean id="testPropertyRead1" class="com.restfulservice.gateway.TestPropertyRead">
<property name="name" value="${name}"/>
<property name="address" value="${address}"/>
</beans>
package com.restfulservice.gateway;
import java.io.File;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
//@Path("/v1/status/*")
@Path("/v1status")
@Component
public class IncomingCall {
final static Logger logger = Logger.getLogger(IncomingCall.class);
public static final String Version = "0.0.1";
@Autowired
@Qualifier("testPropertyRead1")
private TestPropertyRead testPropertyRead;
public TestPropertyRead getTestPropertyRead() {
return testPropertyRead;
}
public void setTestPropertyRead(TestPropertyRead testPropertyRead) {
this.testPropertyRead = testPropertyRead;
}
@GET
@Produces(MediaType.TEXT_HTML)
public String returnTitle()
{
logger.debug("inside returnTitle function call");
return "<p> Java Rest Web Service JSB ....</p>";
}
@Path("/version")
@GET
@Produces(MediaType.TEXT_HTML)
public String returnVersion()
{
return "<p> Java Rest Web Service JSB ....</p>" + "Version:" + Version;
}
@Path("/testspring")
@GET
@Produces(MediaType.TEXT_HTML)
public String testSpring()
{
logger.debug("inside testSpring function call");
logger.info("sai baba is awesome he is making me work, he is my energy");
ApplicationContext context = new ClassPathXmlApplicationContext(
"SpringBeans.xml");
TestSpringSimple obj = (TestSpringSimple) context.getBean("testsprings1");
obj.printHello();
logger.info("going to call callhibernate");
obj.callHibernate();
logger.info("called callhibernate");
return "<p> Java Rest Web Service JSB ...testing spring</p>";
}
@Path("/testconfigreader")
@GET
@Produces(MediaType.TEXT_HTML)
public String testConfigReader()
{
logger.debug("inside testConfigReader function call");
/*ApplicationContext context = new ClassPathXmlApplicationContext(
"ApplicationContext.xml");
TestPropertyRead obj = (TestPropertyRead) context.getBean("testconfig");
*/
//TestPropertyRead testconfig = (TestPropertyRead) TestPropertyRead.getBean("testconfig");
return "<p> Java Rest Web Service JSB ...testing spring config reader "+ testPropertyRead.printAll()
+ "</p>";
//return "<p> Java Rest Web Service JSB ...testing spring config reader "+ ((TestPropertyRead)TestPropertyRead.getBean("testconfig")).printAll()+ "</p>";
}
/**
* Similarly one can download text data also
* @return
*/
@Path("/downloadimage")
@GET
@Produces("image/png")
public Response downloadimage()
{
logger.debug("inside downloadimage function call");
File file = new File("C:\\swamishiva.jpg");
ResponseBuilder response = Response.ok((Object) file);
response.header("Content-Disposition",
"attachment; filename=image_from_server.png");
return response.build();
}
}
===============================================================================
TestPropertyRead.java
package com.restfulservice.gateway;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
@Component
public class TestPropertyRead
{
//private static ApplicationContext CONTEXT;
private String name;
private String address;
public TestPropertyRead()
{
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String printAll() {
System.out.println("name:" + name + " Address:" + address);
return "name:" + name + " Address:" + address;
}
}
我对spring很陌生,但通常会发现,当Autowired属性的指针为空时,这是因为组件扫描失败了。
也许看看这个问题Spring Boot MVC,看看是否有什么帮助?
我总是忘记的一个是@enableAutoConfiguration。
问题内容: 我正在使用Eclipse Ganymede创建一个Web应用程序,但是该项目目前只是一个标准Java项目。我想将其转换为动态Web项目,并且需要这样做。 我曾就编辑.project文件提供了一些建议,但是当我重新启动Eclipse时,它拒绝打开该项目并声称该文件已损坏。项目属性中也没有构面管理选项。 有什么建议? 问题答案: 好。伙计们,我 告诉 你为什么。这是因为这些指南中有很多都遗
我尝试在eclipse中创建一个动态web项目,并将该项目转换为maven项目。我的项目有这样的结构 当我右键单击project>Configure>Convert to Maven project时,我会得到以下错误消息:
问题内容: 我已经使用eclipse中的 m2e插件* 将 Java Web项目 转换为 Maven项目 。现在,我需要将其转换回Java Web项目。现在,如何将其更改回Java Web项目。 * 问题答案: 请尝试以下操作: 在Maven项目上打开上下文菜单 选择“ Maven”->“禁用Maven自然” 希望能有所帮助。
问题内容: 您好,我有以下代码来查看JComboBox中的项目是否是一个类的实例(Persoon)。 item的输出是persoon.name变量的值。所以JComboBox中的项目实际上是字符串。 这就是设置JComboBox列表的方式。 我的问题是..我如何检查这个Persoon对象是否存在并且与JComboBox中的对象相同? 问题答案: 您应该添加到的,当你打电话的对象,不只是名字,所以这
我试图使用Eclipse的从maven开始。但如果我尝试将现有项目更改为Maven项目(),结果是: null 问题可能出在哪里? 更新(生成的pom.xml):
我有一节这样的课 并从外部API向webclient获取数据 我想把数据转换成下面这样。 这是我的尝试 我的方法似乎是同步的。